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