program E; var n,m,i,x,j:int64; begin assign(input,'problem.in'); reset(input); assign(output,'problem.out'); rewrite(output); read(input,n,m); x:=0; j:=0; for i:=1 to n do x:=x+i; for i:=1 to n do begin if x mod m = 0 then j:=j+1; x:=x-n; n:=n-1; end; write(output,j); writeln; close(input); close(output); end.