{Sum NOIP模拟2010-11-19
Author: yangbohua
Time: 2010-11-19}
program suma;
var
f:array[0..100001] of longint;
a,n,k,p,i,j,temp,min:longint;
begin
assign(input,'suma.in');
reset(input);
assign(output,'suma.out');
rewrite(output);
readln(n,k,p);
f[0]:=0;
for i:=1 to n do
begin
read(a);
f[i]:=(f[i-1]+a) mod p;
end;
min:=maxlongint;
for i:=1 to n do
for j:=i to n do
begin
temp:=f[j]-f[i-1];
if temp<0
then temp:=temp+p;
if (temp>=k) and (temp<min) then
begin
min:=temp;
if min=k then
begin
writeln(k);
close(input);
close(output);
halt;
end;
end;
end;
writeln(min);
close(input);
close(output);
end.