Problem: Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.

There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.

Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w ≤ a), (h ≤ b) and (w/h = x/y).

In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.

Input

The first line contains four integers a, b, x, y (1 ≤ a, b, x, y ≤ 10^{18}) — the constraints on the screen width and height, and on the aspect ratio.

Output

Print one integer — the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.

Examples

Input

17 15 5 3


Output

3


Input

14 16 7 22


Output

0


Input

4 2 6 4


Output

1


Input

1000000000000000000 1000000000000000000 999999866000004473 999999822000007597


Output

1000000063

Note

In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).

In the second example, there is no TV set meeting the constraints.

In the third example, there is only one variant: (3, 2).

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;
public class Task {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.flush();out.close();
    }
        static class TaskE {
        class pair{
            int F,S;
            pair(int a,int b){F=a;S=b;}
        }
	 	  public void solve(int testNumber, InputReader in, PrintWriter out) {
 			// int n=in.nextInt(),m=in.nextInt(),d=in.nextInt();
    //         int a[]=new int[n+1];
    //         TreeSet<pair> ts=new TreeSet<>((A,B)->A.F==B.F?A.S-B.S:A.F-B.F);
    //         for(int i=1;i<=n;i++){
    //             ts.add(new pair(in.nextInt(),i));
    //         }
    //         int cnt=0;
    //         while(!ts.isEmpty()){
    //             pair p=ts.first();++cnt;
    //             while(p!=null){
    //                 a[p.S]=cnt;
    //                 ts.remove(p);
    //                 p=ts.ceiling(new pair(p.F+d+1,-1));
    //             }
    //         }
    //         out.println(cnt);
    //         for(int i=1;i<=n;i++)out.print(a[i]+" ");
            // int n=in.nextInt();long h=in.nextLong();
            // pair p[]=new pair[n+1];
            // for(int i=1;i<=n;i++){
            //     p[i]=new pair(in.nextInt(),in.nextInt());
            // }
            // int j=0;long dist=h;
            // long ans=h;
            // for(int i=1;i<=n;i++){
            //     j=Math.max(j,i);
            //     while(j<=n){
            //         if(p[j].F<dist+p[i].F){
            //             dist+=p[j].S-p[j].F;
            //             ++j;
            //         }else break;
            //     }
            //     ans=Math.max(ans,dist);
            //     if(j>i){
            //         dist-=p[i].S-p[i].F;
            //     }
            // }
            // out.print(ans);
            // int n=in.nextInt();
            // ArrayList<Integer> al=new ArrayList<>();
            // long ans=0;
            // for(int i=0;i<n;i++)al.add(in.nextInt());
            // Collections.sort(al);
            // for(int i=1;i<n;i++){
            //     ans+=al.get(i)-al.get(i-1)-1;
            // }
            // out.print(ans);
            long a=in.nextLong(),b=in.nextLong(),x=in.nextLong(),y=in.nextLong();
            long gcd=gcd(x,y);
            x/=gcd;y/=gcd;
            out.print(Math.min(a/x,b/y));
          }
          long gcd(long a,long b){
            if(a%b==0)return b;
            return gcd(b,a%b);
          }
//         pair ja[][];long w[];int from[],to[],c[];
//             void make(int n,int m,InputReader in){
//              ja=new pair[n+1][];w=new long[m];from=new int[m];to=new int[m];c=new int[n+1];
//              for(int i=0;i<m;i++){
//               int u=in.nextInt(),v=in.nextInt();long wt=in.nextLong();
//               c[u]++;c[v]++;from[i]=u;to[i]=v;w[i]=wt;
//              }
//              for(int i=1;i<=n;i++){
//               ja[i]=new pair[c[i]];c[i]=0;
//              }
//              for(int i=0;i<m;i++){
//               ja[from[i]][c[from[i]]++]=new pair(to[i],w[i]);
//               ja[to[i]][c[to[i]]++]=new pair(from[i],w[i]);
//              }
//             }
//        int[] radixSort(int[] f){ return radixSort(f, f.length); }
//	int[] radixSort(int[] f, int n)
//	{
//		int[] to = new int[n];
//		{
//			int[] b = new int[65537];
//			for(int i = 0;i < n;i++)b[1+(f[i]&0xffff)]++;
//			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
//			for(int i = 0;i < n;i++)to[b[f[i]&0xffff]++] = f[i];
//			int[] d = f; f = to;to = d;
//		}
//		{
//			int[] b = new int[65537];
//			for(int i = 0;i < n;i++)b[1+(f[i]>>>16)]++;
//			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
//			for(int i = 0;i < n;i++)to[b[f[i]>>>16]++] = f[i];
//			int[] d = f; f = to;to = d;
//		}
//		return f;
//	}
    }
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;
        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}