program wrong_count;

function gcd(x, y: longint): longint;
var
	t: longint;
begin
	while y <> 0 do begin
		t := x mod y;
		x := y;
		y := t;
	end;
	gcd := x;
end;

var
	n, k: longint;

begin
	reset(input, 'wrong.in');
	rewrite(output, 'wrong.out');

	readln(n, k);
	assert((1 <= n) and (n <= 1000));
	assert((1 <= k) and (k <= 1000000000));

	writeln(n - n div gcd(n, k));

	close(input);
	close(output);
end.