#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const int N = 1e6+10;
int t,n,m,k,l,r,op,x,y;
int f[N];
bool flag;
int dfs(int a,int b){
if(b==0)return 0;
return a/b+dfs(b,a%b);
}
void solve(){
cin>>x>>y;
cout<<dfs(x,y);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}