Vasya is studying number theory. He has denoted a function f(a, b) such that:

  * f(a, 0) = 0; 
  * f(a, b) = 1 + f(a, b - gcd(a, b)), where gcd(a, b) is the greatest common divisor of a and b. 



Vasya has two numbers x and y, and he wants to calculate f(x, y). He tried to do it by himself, but found out that calculating this function the way he wants to do that might take very long time. So he decided to ask you to implement a program that will calculate this function swiftly.

Input

The first line contains two integer numbers x and y (1 ≤ x, y ≤ 1012).

Output

Print f(x, y).

Examples

Input

3 5


Output

3


Input

6 3


Output

1
import java.io.*;
import java.util.*;

public class E implements Runnable{
	public static void main (String[] args) {new Thread(null, new E(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("Go!");

		
//		System.out.println(primeFactors(18));
//		go(5076, 3576432);
//		go(12, 57);
		long x = fs.nextLong(), y = fs.nextLong();
		out.println(solve(primeFactors(x), x, y));
		
		out.close();
	}
	
	ArrayList<Long> primeFactors(long n) {
		ArrayList<Long> res = new ArrayList<>();
		for(long i = 2; i * i <= n; i++) {
			boolean add = false;
			while(n % i == 0) {
				add = true;
				n /= i;
			}
			if(add) res.add(i);
		}
		if(n > 1) res.add(n);
		Collections.sort(res);
		return res;
	}
	
	long solve(ArrayList<Long> factors, long x, long y) {
		int cnt = 0;
		long res = 0;
		boolean print;
		while(y > 0) {
			long g = gcd(x, y);
			//changes when?
			long move = Long.MAX_VALUE;
			for(int i = 0; i < factors.size(); i++) {
				long gcd2 = g * factors.get(i);
				if(x % gcd2 != 0) continue;
				//how many moves?
				long getsTo = y/gcd2 * gcd2;
				long moves = (y-getsTo) / g;
				if(moves < move) {
					move = moves;
				}
			}
			if(move == Long.MAX_VALUE) {
				res += y/g;
				break;
			}
			else {
				res += move;
				y -= g*move;
			}
			cnt++;
		}
		return res;
	}
	
	void go(long a, long b) {
		long res = 0;
		while(b > 0) {
			long g = gcd(a, b);
//			System.out.println(" Subtracting " + g + " b = " + b);
			res++;
			b -= g;
		}
		System.out.println("Moves " + res);
	}

	long gcd (long a, long b) {
		while(b > 0) {
			long temp = b;
			b = a % b;
			a = temp;
		}
		return a;
	}
	
	void sort (int[] a) {
		int n = a.length;
		for(int i = 0; i < 50; i++) {
			Random r = new Random();
			int x = r.nextInt(n), y = r.nextInt(n);
			int temp = a[x];
			a[x] = a[y];
			a[y] = temp;
		}
		Arrays.sort(a);
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}