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