source_code: import java.awt.Point;
  import java.io.BufferedReader;
  import java.io.BufferedWriter;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.OutputStreamWriter;
  import java.io.PrintWriter;
  import java.util.ArrayList;
  import java.util.StringTokenizer;
  
  
  public class A {
  
      static StringTokenizer st;
      static BufferedReader br;
      static PrintWriter pw;
      public static void main(String[] args) throws IOException {
          br = new BufferedReader(new InputStreamReader(System.in));
          pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
          long x = nextLong();
          long y = nextLong();
          long ans = 0;
          while (x > 0 && y > 0) {
              if (x > y) {
                  ans += x / y;
                  x %= y;
              }
              else {
                  ans += y / x;
                  y %= x;
              }
          }
          System.out.println(ans);
      }
      private static int nextInt() throws IOException {
          return Integer.parseInt(next());
      }
      private static long nextLong() throws IOException {
          return Long.parseLong(next());
      }
      private static double nextDouble() throws IOException {
          return Double.parseDouble(next());
      }
      private static String next() throws IOException {
          while (st==null || !st.hasMoreTokens())
              st = new StringTokenizer(br.readLine());
          return st.nextToken();
      }
  }
  