#include<iostream> #include<algorithm> #include<cstdio> using namespace std; long long a,b,c,s=0; int main(){ scanf("%lld",&a); scanf("%lld",&b); while(a>1){ if(b>a){c=a;a=b;b=c;} s+=a/b; a%=b; } if(a!=0){s+=b;} printf("%lld",s); return 0; }