program cogs2170;
var
ch:char;
n:string;
ans,m:int64;
l,i,j:longint;
procedure init;
begin
assign(input,'bigint.in');assign(output,'bigint.out');
reset(input);rewrite(output);
read(ch);
while ch<>' ' do begin
n:=n+ch;
read(ch); end;
readln(m);
end;
begin
init;
for i:=1 to length(n) do begin
ans:=(ans*10+ord(n[i])-48)mod m;
end;
writeln(ans);
close(input);close(output);
end.