import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int gcd = getGCD(n, m); n /= gcd; m /= gcd; System.out.println(getCount(n, m) - 1); } static int getCount(int x, int y) { if (x == 0 || y == 0) { return 0; } if (x > y) { return x / y + getCount(x % y, y); } else { return 1 + getCount(y, x); } } static int getGCD(int x, int y) { if (x % y == 0) { return y; } else { return getGCD(y, x % y); } } }