source_code: import java.io.InputStreamReader;
  import java.io.IOException;
  import java.util.InputMismatchException;
  import java.io.BufferedReader;
  import java.io.OutputStream;
  import java.io.PrintWriter;
  import java.io.Reader;
  import java.io.Writer;
  import java.io.InputStream;
  
  /**
   * Built using CHelper plug-in
   * Actual solution is at the top
   * @author Niyaz Nigmatullin
   */
  public class Main {
  	public static void main(String[] args) {
  		InputStream inputStream = System.in;
  		OutputStream outputStream = System.out;
  		FastScanner in = new FastScanner(inputStream);
  		FastPrinter out = new FastPrinter(outputStream);
  		TaskA solver = new TaskA();
  		solver.solve(1, in, out);
  		out.close();
  	}
  }
  
  class TaskA {
      public void solve(int testNumber, FastScanner in, FastPrinter out) {
          long a = in.nextLong();
          long b = in.nextLong();
          if (a < b) {
              long t = a;
              a = b;
              b = t;
          }
          long ans = 0;
          while (b > 0) {
              ans += a / b;
              long t = a % b;
              a = b;
              b = t;
          }
          out.println(ans);
      }
  }
  
  class FastScanner extends BufferedReader {
  
      public FastScanner(InputStream is) {
          super(new InputStreamReader(is));
      }
  
      public int read() {
          try {
              int ret = super.read();
  //            if (isEOF && ret < 0) {
  //                throw new InputMismatchException();
  //            }
  //            isEOF = ret == -1;
              return ret;
          } catch (IOException e) {
              throw new InputMismatchException();
          }
      }
  
      public String next() {
          StringBuilder sb = new StringBuilder();
          int c = read();
          while (isWhiteSpace(c)) {
              c = read();
          }
          if (c < 0) {
              return null;
          }
          while (c >= 0 && !isWhiteSpace(c)) {
              sb.appendCodePoint(c);
              c = read();
          }
          return sb.toString();
      }
  
      static boolean isWhiteSpace(int c) {
          return c >= 0 && c <= 32;
      }
  
      public long nextLong() {
          return Long.parseLong(next());
      }
  
      public String readLine() {
          try {
              return super.readLine();
          } catch (IOException e) {
              return null;
          }
      }
  
      }
  
  class FastPrinter extends PrintWriter {
  
      public FastPrinter(OutputStream out) {
          super(out);
      }
  
      public FastPrinter(Writer out) {
          super(out);
      }
  
  
  }
  
  