source_code: import java.io.IOException;
  import java.io.OutputStreamWriter;
  import java.io.BufferedWriter;
  import java.util.InputMismatchException;
  import java.io.OutputStream;
  import java.io.PrintWriter;
  import java.util.NoSuchElementException;
  import java.io.Writer;
  import java.math.BigInteger;
  import java.io.InputStream;
  
  /**
   * Built using CHelper plug-in
   * Actual solution is at the top
   * @author Alex
   */
  public class Main {
  	public static void main(String[] args) {
  		InputStream inputStream = System.in;
  		OutputStream outputStream = System.out;
  		InputReader in = new InputReader(inputStream);
  		OutputWriter out = new OutputWriter(outputStream);
  		TaskA solver = new TaskA();
  		solver.solve(1, in, out);
  		out.close();
  	}
  }
  
  class TaskA {
      public long recurse(long a, long b) {
          if (b <= 1) return a;
          return Math.max(a, b)/Math.min(a,b) + recurse(Math.max(a, b) - Math.min(a, b)*(Math.max(a,b)/Math.min(a, b)), Math.min(a, b));
      }
  
      public void solve(int testNumber, InputReader in, OutputWriter out) {
          long a = in.readLong(), b = in.readLong(), i = 0;
  //        while(true) {
  //            if (b <= 1){
  //                i += a;
  //                out.print(i);
  //                return;
  //            }
  //            i++;
  //            long aa = Math.max(a, b);
  //            long bb = Math.min(a, b);
  //            aa -= bb;
  //            a = aa;
  //            b = bb;
  //        }
  //        out.print(i);
          out.print(recurse(a, b));
      }
  }
  
  class InputReader {
  	private InputStream stream;
  	private byte[] buf = new byte[1024];
  	private int curChar;
  	private int numChars;
  	private SpaceCharFilter filter;
  
  	public InputReader(InputStream stream) {
  		this.stream = stream;
  	}
  
  	public int read() {
  		if (numChars == -1)
  			throw new InputMismatchException();
  		if (curChar >= numChars) {
  			curChar = 0;
  			try {
  				numChars = stream.read(buf);
  			} catch (IOException e) {
  				throw new InputMismatchException();
  			}
  			if (numChars <= 0)
  				return -1;
  		}
  		return buf[curChar++];
  	}
  	public long readLong() {
  		int c = read();
  		while (isSpaceChar(c))
  			c = read();
  		int sgn = 1;
  		if (c == '-') {
  			sgn = -1;
  			c = read();
  		}
  		long res = 0;
  		do {
  			if (c < '0' || c > '9')
  				throw new InputMismatchException();
  			res *= 10;
  			res += c - '0';
  			c = read();
  		} while (!isSpaceChar(c));
  		return res * sgn;
  	}
  	public boolean isSpaceChar(int c) {
  		if (filter != null)
  			return filter.isSpaceChar(c);
  		return isWhitespace(c);
  	}
  
  	public static boolean isWhitespace(int c) {
  		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
  	}
  	public interface SpaceCharFilter {
  		public boolean isSpaceChar(int ch);
  	}
  }
  
  class OutputWriter {
  	private final PrintWriter writer;
  
  	public OutputWriter(OutputStream outputStream) {
  		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
  	}
  	public void close() {
  		writer.close();
  	}
  	public void print(long i) {
  		writer.print(i);
  	}
  }
  
  