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.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
 
 
public class q5 {
	
    
  
	
 
	public static void main(String[] args) throws IOException {
	
	Reader.init(System.in);
	PrintWriter out=new PrintWriter(System.out);
	long x=Reader.nextLong();
	long y=Reader.nextLong();
	long ans=0;
	if(x==1) ans=y;
	else {
	ArrayList<Long> pf=new ArrayList<Long>();
	long xx=x;
	long r=(long) Math.sqrt(xx);
	for(long i=1;i<=r;i++) {
		if(xx%i==0) {
			if(i!=1)
			pf.add(i);
			if(xx/i!=i) pf.add(xx/i);
		}
	}
	long divchosen=1;
	while(y!=0) {
		long v=1;
		long dist=Long.MAX_VALUE;
		for(long l:pf) {
			if(l!=divchosen) {
			long c=y/l*l;
			long d=y-c;
			if(d<=dist) {
				dist=d;
				v=l;
			}
			}
		}
		if(v==1) {
			if(x<y) {
				ans+=(y-x)/divchosen+1;
				y=0;
			}
			else {
				ans+=1;
				y=0;
			}
			
		}
		ans+=(y-y/v*v)/divchosen;
		y=y/v*v;
		divchosen=v;
		ArrayList<Long> pf2=new ArrayList<Long>();
		for(long l:pf) {
			if(l%v==0) pf2.add(l);
		}
		pf=pf2;
		
	}
	}
	out.print(ans);	
	
	
	
	
	out.flush();
	}
}



 
 
 
class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    /** call this method to initialize reader for InputStream */
    static void init() throws IOException {
    	 reader = new BufferedReader(
                 new FileReader("detect.in"));
    tokenizer = new StringTokenizer("");
    }
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
    /** get next word */
    static String nextLine() throws IOException{
    	return reader.readLine();
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }
    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}