function gcd (a, b:integer):integer;
begin
  if b=0 then gcd:=a else gcd:=gcd (b, a mod b);
end;

var n, k:integer;

begin
  reset (input, 'wrong.in'); rewrite (output, 'wrong.out');
  read (n, k);
  write (n - n div gcd (n, k)); 
end.