import java.io.IOException; public class Main { public static void main(String[] args) { int M = nextInt(); int N = nextInt(); int gcd = gcd(M, N); M /= gcd; N /= gcd; int magic = 0; while (N != M || N != 1) { if (M < N) { int tmp = M; M = N; N = tmp; } else { M -= N; } magic++; } System.out.println(magic); } static int gcd(int a, int b) { // b=0ならaを最大公約数として終了 if (b == 0) { return a; } else { // a÷bのあまりをb、元のbをaとして2.にもどる return gcd(b, a % b); } } static int nextInt() { int c; try { c = System.in.read(); while (c != '-' && (c < '0' || c > '9')) c = System.in.read(); if (c == '-') return -nextInt(); int res = 0; while (c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = System.in.read(); } return res; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return -1; } }