program suma(input,output);
var
i,j,n,k,p,ans,t:longint;
a:array[1..100000]of longint;
sum:array[0..100000]of int64;
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]);
sum[i]:=sum[i-1]+a[i];
end;
ans:=maxlongint;
for i:=0 to n-1 do
for j:=i to n do
begin
t:=(sum[j]-sum[i])mod p;
if (t>=k)and(t<ans) then
ans:=t;
end;
writeln(ans);
close(input);
close(output);
end.