m, n = map(int, input().split()) cnt = 0 while True: if m < n: m, n = n, m cnt += 1 elif m == n: print(cnt) exit() else: t = (m-n)//n m -= n*t cnt += t if m > n: m -= n cnt += 1