import math M,N = map(int,input().split()) gc = math.gcd(M,N) M,N = M//gc,N//gc cnt = 0 while N!=1: if M