using System; class Program { static void Main() { var tmp = Console.ReadLine().Split(); int m = int.Parse(tmp[0]); int n = int.Parse(tmp[1]); int d = Gcd(m, n); m /= d; n /= d; int cnt = 0; while (true) { if (m == 1 && n == 1) break; if (n > m) { int l = m; m = n; n = l; cnt++; } else { m -= n; cnt++; } } Console.WriteLine(cnt); } static int Gcd(int a, int b) { if (a < b) return Gcd(b, a); int d = 0; do { d = a % b; a = b; b = d; } while (d != 0); return a; } }