#include <iostream>
#include <cstdio>
using namespace std;
const int N = 1e2 + 5;
int f[N][N];
int main()
{
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; ++i)
{
int t;
scanf("%d", &t);
for (int j = 0; j < m; ++j)
f[i][j] = f[i-1][j];
for (int j = 0; j < m; ++j)
{
if (f[i-1][j] % m == j)
f[i][(j+t)%m] = max(f[i][(j+t)%m], f[i-1][j]+t);
}
}
printf("%d", f[n][0]);
return 0;
}