var
n,k,x,p,min,i,j:longint;
a,s:array[0..100000]of longint;
begin
assign(input,'suma.in'); reset(input);
assign(output,'suma.out'); rewrite(output);
readln(n,k,p);
for i:=1 to n do
begin
readln(a[i]);
s[i]:=(s[i-1]+a[i]) mod p;
end;
min:=maxlongint;
for i:=0 to n do
for j:=i+1 to n do
begin
x:=(s[j]-s[i]+p) mod p;
if (x>=k)and(x<min) then min:=x;
end;
writeln(min);
close(input);
close(output);
end.