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:
//Author: Mo Abjal, MJP Rohilkhand University Bareilly, UP, India 2018.
///////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////********************//////////////////////////////////////////////
/////////////////////////////////////////*     S0LUT10N     *//////////////////////////////////////////////
/////////////////////////////////////////********************//////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
import java.util.*;
import java.io.*;
import java.text.*;
import java.math.*;
public class Main{
	public static StringTokenizer token = new StringTokenizer("");
	public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static PrintWriter output = new PrintWriter(System.out);
	public static void main(String[] afzal) throws Exception {		
		long A = nl();
		long B = nl();
		long X = nl();
		long Y = nl();
		long gcd = gcd(X,Y);
		long x = X/gcd;
		long y = Y/gcd;
		output.println(Math.min(A/x,B/y)); output.close();
	}
	public static long gcd(long a,long b){
		if(b==0) return a;
		else return gcd(b,a%b);
	}
	public static String pc(char c){
		return Character.toString(c);
	} 
	public static Integer pci(char c){
		return pi(Character.toString(c));
	}
	public static Integer pi(String str){
		return Integer.parseInt(str);
	}
	public static Long pl(String str){
		return Long.parseLong(str);
	}
	public static String ps(Integer N){
		return Integer.toString(N);
	}
	public static char[] pcc(String str){
		return str.toCharArray();
	}
	public static Integer ni() throws IOException{
		if(!token.hasMoreElements()){
			token = new StringTokenizer(br.readLine());
		}
		return Integer.parseInt(token.nextToken());
	}
	public static Long nl() throws IOException{
		if(!token.hasMoreElements()){
			token = new StringTokenizer(br.readLine());
		}
		return Long.parseLong(token.nextToken());
	}
	public static Double nd() throws IOException{
		if(!token.hasMoreElements()){
			token = new StringTokenizer(br.readLine());
		}
		return Double.parseDouble(token.nextToken());
	}
	public static String ns() throws IOException{
		if(!token.hasMoreElements()){
			token = new StringTokenizer(br.readLine());
		}
		return token.nextToken();
	}
	public static Integer[] ai(int N) throws IOException{
		Integer A[] = new Integer[N];
		token = new StringTokenizer(br.readLine());
		for(int i=0;i<A.length;i++){
			A[i] = pi(token.nextToken());
		}
		return A;
	}
	public static long[] al(int N) throws IOException{
		long A[] = new long[N];
		token = new StringTokenizer(br.readLine());
		for(int i=0;i<N;i++){
			A[i] = Long.parseLong(token.nextToken());
		}
		return A;
	}
	public static char[][] acc(int N,int M) throws IOException{
		char C[][] = new char[N][M];
		for(int i=0;i<N;i++){
			token = new StringTokenizer(br.readLine());
			String s = token.nextToken();
			for(int j=0;j<M;j++){
				C[i][j] = s.charAt(j);
			}
		}
		return C;
	}
	public static String[] as(int N) throws IOException{
		String S[] = new String[N];
		token = new StringTokenizer(br.readLine());
		for(int i=0;i<S.length;i++){
			S[i] = token.nextToken();
		}
		return S;
	}
	public static double ncr(int n, int r){
		if(n==r) return 1;
		else
		return (fact(n)/(fact(r)*fact(n-r)));
	}
	public static long fact(long N){
		long fact = 1;
		for(int i=1;i<=N;i++){
			fact = fact * i;
		}
		return fact;
	}
	public static BigInteger factB(int N){
		BigInteger b = new BigInteger("1");
		for(int i=1;i<=N;i++){
			b = b.multiply(BigInteger.valueOf(i));
		}
		return b;
	}
	public static long sod(long N){
		long sum = 0;
		while(N>0){
			long x = N%10;
			sum = sum + x;
			N = N/10;
		}
		return sum;
	}
	public static Integer cd(long N){
		int count=0;
		while(N>0){
			N = N/10; count++;
		}
		return count=0;
	}
}
class Pair implements Comparable{
	int a,b;
	public Pair(int a,int b){
		this.a = a;
		this.b = b;
	}
	public int compareTo(Object p){
		Pair pa = (Pair)p;
		//if(this.a==pa.a) return this.b - pa.b;
		return this.a - pa.a;
	} 
}class Pair3 implements Comparable{
	int a,b,c;
	public Pair3(int a,int b,int c){
		this.a = a;
		this.b = b;
		this.c = c;
	}
	public int compareTo(Object p){
		Pair pa = (Pair)p;
		//if(this.a==pa.a) return this.b - pa.b;
		return this.a - pa.a;
	} 
}
//Copyright Reserved - Mo Abjal.