from math import gcd M,N = map(int,input().split()) g = gcd(M, N) M //= g N //= g ans = 0 while M != N: if M < N: M,N = N,M else: M -= N ans += 1 print(ans)