#include using namespace std; typedef long long ll; ll solve(int M, int N){ if(M < N) return solve(N, M) + 1; if(M % N == 0) return M / N - 1; return M / N + solve(M % N, N); } int main(){ int M, N; cin >> M >> N; cout << solve(M, N) << endl; return 0; }