program zzn;
var
ans,i,j,n,p,k:longint;
a:array[1..100000]of longint;
sum:array[0..100000]of qword;
procedure init;
begin
assign(input,'suma.in');
reset(input);
assign(output,'suma.out');
rewrite(output);
readln(n,k,p);
sum[0]:=0;
for i:=1 to n do
begin
readln(a[i]);
sum[i]:=sum[i-1]+a[i];
end;
end;
procedure closef;
begin
close(input);
close(output);
end;
function cal(x,y:longint):qword;
begin
cal:=sum[y]-sum[x-1];
end;
procedure main;
var
s:qword;
begin
ans:=maxlongint;
for i:=1 to n-1 do
for j:=i+1 to n do
begin
s:=cal(i,j);
if s mod p>=k then
if s mod p<ans then ans:=s mod p;
end;
writeln(ans);
end;
begin
init;
main;
closef;
end.