source_code: import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.BufferedReader;
  import java.io.OutputStream;
  import java.io.PrintWriter;
  import java.util.StringTokenizer;
  import java.io.InputStream;
  
  /**
   * Built using CHelper plug-in
   * Actual solution is at the top
   * @author dudkamaster
   */
  public class Main {
      public static void main(String[] args) {
          InputStream inputStream = System.in;
          OutputStream outputStream = System.out;
          InputReader in = new InputReader(inputStream);
          PrintWriter out = new PrintWriter(outputStream);
          TaskA solver = new TaskA();
          solver.solve(1, in, out);
          out.close();
      }
  }
  
  class TaskA {
  
      public void solve(int testNumber, InputReader in, PrintWriter out) {
          long a = in.nextLong();
          long b = in.nextLong();
          long ans = 0;
          while (a > 0 && b > 0){
              if (a < b){
                  long t = a;
                  a = b;
                  b = t;
              }
              ans += a/b;
              a %= b;
          }
          out.print(ans);
      }
  }
  
  class InputReader {
      private BufferedReader reader;
      private StringTokenizer tokenizer;
  
      public InputReader (InputStream stream){
          reader = new BufferedReader(new InputStreamReader(stream));
          tokenizer = null;
      }
  
      public String next(){
          while (tokenizer == null || !tokenizer.hasMoreTokens()){
              try{
                  tokenizer = new StringTokenizer(reader.readLine());
              } catch (Exception e){
                  throw new RuntimeException(e);
              }
          }
          return tokenizer.nextToken();
      }
  
      public long nextLong(){
          return Long.parseLong(next());
      }
  
      }
  