n,d = map(int,input().split()) def cal(x,y): if y == 0: return x return cal(y,x%y) print(n//cal(n,d)-1)