program chebn;
var
a,c:array[1..200] of longint;
q,lena,code,i,j,x,b:longint;
n1,n2:string;
begin
assign(input,'bigint.in'); reset(input);
assign(output,'bigint.out'); rewrite(output);
readln(n1);
lena:=length(n1);
q:=pos(' ',n1);
n2:=copy(n1,q+1,lena);
delete(n1,q,lena);
lena:=length(n1);
for i:=1 to lena do a[i]:=ord(n1[i])-48;
val(n2,b);
x:=0;
for i:=1 to lena do begin
c[i]:=(x*10+a[i]) div b;
x:=(x*10+a[i]) mod b;
end;
writeln(x);
close(input); close(output);
end.