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.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.List;
 import java.util.*;
 public class realfast implements Runnable 
  {
    private static final int INF = (int) 1e9;
    long in= (long)Math.pow(10,9)+7;
    long fac[]= new long[3000];
    public  void solve() throws IOException 
    {
       long x = readLong(); 
       long y = readLong();
       ArrayList<Long> arr = new ArrayList<>();

       long root = (long)Math.pow(x,0.5);
       for(long i=1;i<=root;i++)
       {
        if(x%i==0)
        {
            arr.add(i);
            long gal = x/i;
          if(gal!=i)
          {
            arr.add(gal);
          }
         }
        
       }
       
       Collections.sort(arr);

       long gcd = gcd(x,y);

       long ini = y;
     //  out.println(gcd+" "+ini);
       long count =0;
       while(ini>0)
       {
            long max =0;
            long lo = gcd;
            for(int j =0;j<arr.size();j++)
            {
                long val2 = arr.get(j);
                if(val2>gcd&&(val2%gcd)==0)
                {
                   long cal = val2*(ini/val2);
                   if(cal>=max)
                   {
                    max=cal;
                    lo = val2;
                   }
                }
            }

            count = count + (ini-max)/gcd;
            ini = max;
            gcd = lo;
       }

       out.println(count);

    }
    public int seg(int seg[], int left, int right, int index, int val)
    {
        if(left==right)
        {
            seg[index]=1;
            return 1;
        }
        int mid = left+(right-left)/2;

        if(val<=mid)
        {
            seg(seg,left,mid,2*index+1,val);
        }
        else
        {
            seg(seg,mid+1,right,2*index+2,val);
        }
        seg[index]= seg[2*index+1]+seg[2*index+2];
        return seg[index];
    }
    public int val(int seg[], int left , int right, int l , int r,int index)
    {
            if(left>r||right<l)
            {
               return 0;
            }
            int mid = left+(right-left)/2;
            if(left>=l&&right<=r)
            return seg[index];

            return val(seg,left,mid,l,r,2*index+1)+val(seg,mid+1,right,l,r,2*index+2);
    }
    public long gcd(long a , long b )
    {
      if(a<b)
      {
        long t =a;
        a=b;
        b=t;
      }
      if(a%b==0)
        return b ;
      return gcd(b,a%b);
    }
    public long pow(long n , long p,long m)
    {
         if(p==0)
            return 1;
        long val = pow(n,p/2,m);;
        val= (val*val)%m;
        if(p%2==0)
            return val;
        else
            return (val*n)%m;
    }
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public static void main(String[] args) {
        new Thread(null, new realfast(), "", 128 * (1L << 20)).start();
    }
 
    private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    private BufferedReader reader;
    private StringTokenizer tokenizer;
    private PrintWriter out;
 
    @Override
    public void run() {
        try {
            if (ONLINE_JUDGE || !new File("input.txt").exists()) {
                reader = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                reader = new BufferedReader(new FileReader("input.txt"));
                out = new PrintWriter("output.txt");
            }
            solve();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                // nothing
            }
            out.close();
        }
    }
 
    private String readString() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
 
    @SuppressWarnings("unused")
    private int readInt() throws IOException {
        return Integer.parseInt(readString());
    }
 
    @SuppressWarnings("unused")
    private long readLong() throws IOException {
        return Long.parseLong(readString());
    }
 
    @SuppressWarnings("unused")
    private double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }
}
class edge implements Comparable<edge>{
    int val ;
    int color;
    
    edge(int u, int v)
    {
       this.val=u;
       this.color=v;
    }
    public int compareTo(edge e)
    {
        return this.val-e.val;
    }
}