# -*- coding: utf-8 -*- #yuki_141 m,n=map(int,raw_input().split()) count=0 while m!=n: if m==1: count+=n break if n==1: count+=m-1 break if m>n: temp=(m-1)/n count+=temp m-=temp*n else: count+=1 m,n=n,m print count