#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using LL = long long;
constexpr int N = 2e5 + 5;
int n, m;
int a[20];
void solve() {
cin >> n >> m;
for (int i = 0; i < n; ++i)cin >> a[i];
int res = 0;
for (int i = 1, s; i < 1 << n; ++i) {
s = 0;
for (int j = 0; j < n; ++j)
if (i >> j & 1)s = (s + a[j]) % m;
res = max(res, s);
}
cout << res << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int tt = 1;
// cin >> tt;
while (tt--) solve();
}