#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int n,p;
int a[1000001];
int tz[1000001];
int fs[1000001];
int main()
{
int i,max;
//freopen("number.in","r",stdin);
//freopen("number.out","w",stdout);
scanf ("%d%d",&n,&p);
for (i=1;i<=n;i++)
scanf ("%d",&a[i]);
tz[1]=a[1];
for (i=2;i<=n;i++)
{
if (tz[i-1]+a[i]>a[i])
tz[i]=tz[i-1]+a[i];
else
tz[i]=a[i];
}
fs[1]=tz[1];
max=fs[1]+tz[1];
for (i=2;i<=n;i++)
{
fs[i]=max;
if (max<fs[i]+tz[i]&&i!=n)
max=fs[i]+tz[i];
}
max=-2000000000;
for (i=1;i<=n;i++)
{
if (max<fs[i])
max=fs[i];
}
if (max<0)
{
max=abs(max)%p;
printf ("-%d\n",max);
}
else
{
max=max%p;
printf ("%d\n",max);
}
while (1);
return 0;
}