const
  inpfile = 'wrong.in';
  outfile = 'wrong.out';
type
  int = longint;
var
  n,k:int;

function nod(a,b:int):int;
begin
  while (a>0) and (b>0) do
  begin
    if (a>b) then
      a:=a mod b
    else
      b:=b mod a     
  end;
  if (a>b) then
    nod:=a
  else
    nod:=b
end;

begin
  assign(input,inpfile);reset(input);
  assign(output,outfile);rewrite(output);

  read(n,k);
  
  writeln(n-n div nod(n,k));

  close(output)
end.