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: $\frac{w}{h} = \frac{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 \le a)$, $(h \le b)$ and $(\frac{w}{h} = \frac{x}{y})$.

In other words, Monocarp wants to determine the number of TV sets having aspect ratio $\frac{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 \le a, b, x, y \le 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)$.

Difficulty: EASY

Solutions:
(a, b, x, y) = map(int, input().split())
from math import gcd
c = gcd(x, y)
x = x // c
y = y // c
print(min(a // x, b // y))


def read():
	return list(map(int, input().split()))
(a, b, c, d) = read()

def gcd(x, y, big=False):
	if not big:
		sum = x + y
		x = max(x, y)
		y = sum - x
	if y == 0:
		return x
	else:
		return gcd(y, x % y, True)
e = gcd(c, d)
c = c // e
d = d // e
print(str(min(a // c, b // d)))


import math
I = lambda : map(int, input().split())
(a, b, x, y) = I()
g1 = math.gcd(x, y)
x = x // g1
y = y // g1
print(min(a // x, b // y))


def check(A, B, X, Y, mid):
	if X * mid <= A and Y * mid <= B:
		return True
	return False

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
a = list(map(int, input().strip().split(' ')))
(A, B, X, Y) = (a[0], a[1], a[2], a[3])
lw = 0
hg = 10 ** 20
g = gcd(X, Y)
X = X // g
Y = Y // g
while lw <= hg:
	mid = (lw + hg) // 2
	flag = check(A, B, X, Y, mid)
	if flag == True:
		if mid == 0:
			print('0')
			break
		if check(A, B, X, Y, mid + 1) == False:
			print(mid)
			break
	if flag == True:
		lw = mid + 1
	else:
		hg = mid - 1


def gcd(a, b):
	while a != 0 and b != 0:
		if a > b:
			a = a % b
		else:
			b = b % a
	return a + b
(a, b, x, y) = map(int, input().split())
delim = gcd(x, y)
(x, y) = (x // delim, y // delim)
print(min([a // x, b // y]))


def findNOD(a, b):
	while a != 0 and b != 0:
		if a > b:
			a = a % b
		else:
			b = b % a
	return a + b
inp = input().split()
a = int(inp[0])
b = int(inp[1])
x = int(inp[2])
y = int(inp[3])
nodOfXY = findNOD(x, y)
x = x // nodOfXY
y = y // nodOfXY
print(min(a // x, b // y))


(a, b, x, y) = map(int, input().split())
import math

def reduce_fraction(x, y):
	k = math.gcd(x, y)
	return (x // k, y // k)
(x, y) = reduce_fraction(x, y)
print(min(a // x, b // y))


import math
(a, b, x, y) = list(map(int, input().split()))
g = math.gcd(x, y)
x = x // g
y = y // g
print(min(a // x, b // y))


import math
(a, b, x, y) = map(int, input().split())
div = int(math.gcd(x, y))
x //= div
y //= div
ans = min(a // x, b // y)
print(ans)


def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
(a, b, x, y) = map(int, input().split())
if gcd(x, y) != 1:
	rod = gcd(x, y)
	while rod != 1:
		x = x // rod
		y = y // rod
		rod = gcd(x, y)
mul = 0
print(min(a // x, b // y))


(a, b, x, y) = map(int, input().split())
x1 = x
y1 = y
while x != 0 and y != 0:
	if x > y:
		x = x % y
	else:
		y = y % x
x1 //= x + y
y1 //= x + y
print(min(a // x1, b // y1))


(a, b, x, y) = [int(el) for el in input().split()]
xx = x
yy = y
while xx % yy != 0 and yy % xx != 0:
	if xx > yy:
		xx = xx - yy * int(xx / yy)
	else:
		yy = yy - xx * int(yy / xx)
p = min(xx, yy)
x = x / p
y = y / p
if a < x or b < y:
	print('0')
	raise SystemExit()
out = min(a / x, b / y)
print(int(out))


(a, b, x, y) = map(int, input().split())
m = x
n = y
while m != 0 and n != 0:
	if m > n:
		m = m % n
	else:
		n = n % m
t = m + n
x //= t
y //= t
q = a // x
w = b // y
if q < w:
	print(q)
else:
	print(w)


def evc(a, b):
	while b:
		a %= b
		(a, b) = (b, a)
	return a
(n, m, x, y) = list(map(int, input().split()))
h = evc(x, y)
print(min(n // (x // h), m // (y // h)))


(a, b, x, y) = map(int, input().split())

def gcd(p, q):
	if q == 0:
		return p
	else:
		return gcd(q, p % q)
print(min(a // (x // gcd(x, y)), b // (y // gcd(x, y))))


from math import gcd
(a, b, x, y) = list(map(int, input().split()))
l = gcd(x, y)
p = x / l
r = y / l
sa = a // p
ba = b // r
print(int(min(sa, ba)))


import math
import sys
(a, b, x, y) = list(map(int, input().split()))
g = math.gcd(x, y)
x //= g
y //= g
l = 0
r = 10 ** 18
while r - l > 1:
	mid = (r + l) // 2
	if x * mid > a or y * mid > b:
		r = mid
	else:
		l = mid
if x * r > a or y * r > b:
	print(l)
else:
	print(r)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [tuple(map(int, l.split())) for l in sys.stdin]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	(a, b, x, y) = LI()
	g = math.gcd(x, y)
	x //= g
	y //= g
	t = a // x
	u = b // y
	return min(t, u)
print(main())


import sys
import math
sys.setrecursionlimit(10000)
ns = lambda : sys.stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : [int(x) for x in ns().split()]
nall = lambda : [int(x) for x in sys.stdin.readlines()]
sall = lambda : sys.stdin.readlines()

def main():
	(a, b, x, y) = na()
	d = math.gcd(x, y)
	x //= d
	y //= d
	print(min(a // x, b // y))
main()


def gcd(a, b):
	while a != 0 and b != 0:
		t = a % b
		a = b
		b = t
	return a

def main():
	[a, b, x, y] = list(map(int, str.split(input())))
	tmp = gcd(x, y)
	x /= tmp
	y /= tmp
	ans = min(int(a / x), int(b / y))
	print(ans)
main()


(w_max, h_max, a, b) = map(int, input().split(' '))
(x, y) = (a, b)
while x != 0 and y != 0:
	if x > y:
		x = x % y
	else:
		y = y % x
nod = x + y
if nod == 1:
	(x, y) = (a, b)
else:
	(x, y) = (a // nod, b // nod)
cond1 = w_max // x
cond2 = h_max // y
if cond1 > cond2:
	print(cond2)
else:
	print(cond1)


ch = input()
ch = ch.split()
(a, b, x, y) = (int(ch[0]), int(ch[1]), int(ch[2]), int(ch[3]))
(q, r) = (x, y)
q = x
r = y
if q < r:
	(q, r) = (r, q)
while r != 0:
	if q % r == 0:
		break
	(q, r) = (r, q % r)
(x, y) = (x // r, y // r)
print(min(a // x, b // y))


import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
import heapq
mod = 10 ** 9 + 7

def ri(flag=0):
	if flag == 0:
		return [int(i) for i in input().split()]
	else:
		return int(input())
(a, b, x, y) = ri()
from math import gcd
le = gcd(x, y)
x = x // le
y = y // le
print(min(a // x, b // y))


from fractions import Fraction
inpt = list(map(int, input().split()))
a = inpt[0]
b = inpt[1]
x = inpt[2]
y = inpt[3]
count = 0
frac = Fraction(x, y)
x = frac._numerator
y = frac.denominator
ceil_w = a
ceil_h = b
ceil_w = (ceil_w - ceil_w % x) // x
ceil_h = (ceil_h - ceil_h % y) // y
count = min(ceil_h, ceil_w)
print(count)


def gcd(x, y):
	if not x % y:
		return y
	else:
		return gcd(y, x % y)
(a, b, x, y) = map(int, input().split())
n = gcd(x, y)
print(min(a // (x // n), b // (y // n)))


def compute_gcd(x, y):
	if y == 0:
		return x
	else:
		return compute_gcd(y, x % y)
(a, b, x, y) = map(int, input().split())
gcd = compute_gcd(x, y)
x /= gcd
y /= gcd
(num_x, num_y) = (x, y)
mx = int(a / x)
my = int(b / y)
print(min(mx, my))


from math import gcd
h1 = lambda : list(map(int, input().split()))
(a, b, x, y) = h1()
g = gcd(x, y)
print(min(a // int(x / g), b // int(y / g)))


import math
values = list(map(int, input().split()))
gcd = math.gcd(values[2], values[3])
small = [values[2] / gcd, values[3] / gcd]
a1 = int(values[0] / small[0])
a2 = int(values[1] / small[1])
print(min(a1, a2))


import math

def read():
	return [int(v) for v in input().split()]

def main():
	(a, b, x, y) = read()
	g = math.gcd(x, y)
	x //= g
	y //= g
	print(min(a // x, b // y))
main()


(a, b, x, y) = map(int, input().split())

def GCD(m, n):
	if m % n == 0:
		return n
	else:
		return GCD(n, m % n)
g = GCD(max(x, y), min(x, y))
(x, y) = (x / g, y / g)
print(int(min(a // x, b // y)))


import math

def main():
	(a, b, x, y) = map(int, input().split())
	d = math.gcd(x, y)
	x //= d
	y //= d
	print(min(a // x, b // y))
exit(main())


from math import gcd
arr = [int(x) for x in input().split()]
a = arr[0]
b = arr[1]
x = arr[2]
y = arr[3]
g = gcd(x, y)
x = x // g
y = y // g
print(min(a // x, b // y))


import math
X = list(map(int, input().split()))
print(min(X[0] // (X[2] // math.gcd(X[2], X[3])), X[1] // (X[3] // math.gcd(X[2], X[3]))))


def HCF(a, b):
	if b == 0:
		return a
	return HCF(b, a % b)
(a, b, x, y) = map(int, input().split())
hcf = HCF(x, y)
x = x // hcf
y = y // hcf
print(min(a // x, b // y))


def gcd(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a
(a, b, x, y) = map(int, input().split())
q = gcd(x, y)
x //= q
y //= q
print(min(a // x, b // y))


from math import gcd
(a, b, x, y) = [int(i) for i in input().split()][:4]
div = gcd(x, y)
w = x // div
h = y // div
print(min(a // w, b // h))


from fractions import Fraction as F
(a, b, x, y) = map(int, input().split())
k = F(x, y)
(x, y) = (k.numerator, k.denominator)
print(min(a // x, b // y))


cnt = lambda s, x: s.count(x)
ii = lambda : int(input())
si = lambda : input()
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
import math
(a, b, x, y) = f()
g = math.gcd(x, y)
x //= g
y //= g
print(min(a // x, b // y))


import math
(a, b, x, y) = map(int, input().split())
d = math.gcd(x, y)
x /= d
y /= d
print(int(min(a // x, b // y)))


from fractions import Fraction
(a, b, x, y) = list(map(int, input().split()))
pocz = 1
kon = 1e+18 + 5
srd = 0
f = Fraction(x, y)
while kon - pocz > 1:
	srd = (kon + pocz) // 2
	if f.numerator * srd <= a and f.denominator * srd <= b:
		if pocz == srd:
			print(int(pocz))
			exit()
		pocz = srd
	else:
		kon = srd
if srd == 2:
	if f.numerator * 2 <= a and f.denominator * 2 <= b:
		pass
	elif f.numerator <= a and f.denominator <= b:
		pocz = 1
	else:
		pocz = 0
print(int(pocz))


(a, b, x, y) = map(int, input().split())
masx = x
masy = y
if y > x:
	tmp = y
	y = x
	x = tmp
while x % y:
	(x, y) = (y, x % y)
(x, y) = (masx // y, masy // y)
print(min(a // x, b // y))


def co(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
l = [int(x) for x in input().split()]
m = co(l[2], l[3])
l[2] = l[2] // m
l[3] = l[3] // m
print(min(l[0] // l[2], l[1] // l[3]))


def gcd(a, b):
	return a if b == 0 else gcd(b, a % b)
(a, b, x, y) = map(int, input().split(' '))
g = gcd(x, y)
x //= g
y //= g
print(min(a // x, b // y))


def gcd(a, b):
	return gcd(b, a % b) if b else a
(a, b, x, y) = map(int, input().split())
k = gcd(x, y)
x //= k
y //= k
result = min(a // x, b // y)
print(result)


(a, b, x, y) = map(int, input().split())

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def lcm(a, b):
	return a // gcd(a, b) * b
tmp = x // gcd(x, y)
y = y // gcd(x, y)
x = tmp
add_x = x
add_y = y
count = 0
print(min(a // x, b // y))


def gcd(a, b):
	while b > 0:
		c = a
		a = b
		b = c % b
	return a
nums = list(map(int, input().split()))
a = nums[0]
b = nums[1]
x = nums[2]
y = nums[3]
h = min(b, a * y // x)
w = min(a, b * x // y)
d = gcd(x, y)
x = x // d
y = y // d
ans = min(w // x, h // y)
print(ans)


def gcd(a, b):
	if not b:
		return a
	return gcd(b, a % b)
(a, b, x, y) = map(int, input().split())
g = gcd(x, y)
x //= g
y //= g
print(min(a // x, b // y))


from math import gcd
(x, y, a, b) = [int(x) for x in input().split()]
gc = gcd(a, b)
a = a // gc
b = b // gc
print(min(x // a, y // b))


import math
(a, b, x, y) = map(int, input().split())
s = math.gcd(x, y)
x = x // s
y = y // s
n = a // x
t = b // y
print(min(n, t))


def gcd(a, b):
	return abs(a) if b == 0 else gcd(b, a % b)
res = 0
(a, b, x, y) = [int(i) for i in input().split()]
d = gcd(x, y)
x = x // d
y = y // d
print(min(a // x, b // y))


def NOD(x, y):
	while x != 0:
		y %= x
		(x, y) = (y, x)
	return y
(a, b, x, y) = map(int, input().split())
k = NOD(x, y)
x //= k
y //= k
print(min(a // x, b // y))


def gcd(a, b):
	if a % b == 0:
		return b
	else:
		return gcd(b, a % b)
ins = input().split(' ')
a = int(ins[0])
b = int(ins[1])
x = int(ins[2])
y = int(ins[3])
d = gcd(x, y)
x = x / d
y = y / d
if a / b >= x / y:
	print(int(b / y))
else:
	print(int(a / x))


import math
l = list(map(int, input().split()))
a = l[0]
b = l[1]
x = l[2]
y = l[3]
g = math.gcd(x, y)
x //= g
y //= g
print(min(a // x, b // y))


from math import gcd
(a, b, x, y) = map(int, input().strip().split())
factor = gcd(x, y)
if factor > 1:
	x = x // factor
	y = y // factor
count1 = a // x
count2 = b // y
if count1 < count2:
	count = count1
else:
	count = count2
print(count)


def gcd(a, b):
	while b != 0:
		a %= b
		(a, b) = (b, a)
	return a
(a, b, x, y) = [int(i) for i in input().split()]
g = gcd(x, y)
x //= g
y //= g
print(min(a // x, b // y))


from math import gcd
(a, b, x, y) = map(int, input().split())
p = gcd(x, y)
x //= p
y //= p
b = min(b, a * y // x)
if a < x or b < y:
	print(0)
else:
	print((b - y) // y + 1)


from math import gcd
(a, b, x, y) = map(int, input().split())
z = gcd(x, y)
x = int(x / z)
y = int(y / z)
ans = min(int(a // x), int(b // y))
print(ans)


def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
(n, m, a, b) = map(int, input().split())
p = gcd(a, b)
a = a // p
b = b // p
t1 = n // a
t2 = m // b
print(min(t1, t2))


(a, b, x, y) = map(int, input().split())

def hcfnaive(a, b):
	if b == 0:
		return a
	else:
		return hcfnaive(b, a % b)
s = hcfnaive(x, y)
h = x // s
c = y // s
k = a // h
z = b // c
if k != 0 and z != 0:
	print(min(k, z))
else:
	print(0)


import math
(a, b, c, d) = map(int, input().split())
divisor = math.gcd(c, d)
c //= divisor
d //= divisor
print(min(a // c, b // d))


import fractions
(a, b, c, d) = map(int, input().split())
x = fractions.Fraction(c, d)
print(min(a // x.numerator, b // x.denominator))


def gcd(a, b):
	while b > 0:
		temp = a % b
		a = b
		b = temp
	return a
(a, b, x, y) = map(int, input().split())
gc = gcd(x, y)
x2 = x // gc
y2 = y // gc
x4 = a // x2
y4 = b // y2
if x4 * y2 <= b:
	print(x4)
elif y4 * x2 <= a:
	print(y4)
else:
	print(0)


import math
(a, b, x, y) = map(int, input().strip().split(' '))
temp = math.gcd(x, y)
x //= temp
y //= temp
print(min(a // x, b // y))


(a, b, xx, yy) = map(int, input().split())
x = xx
y = yy
while x != 0 and y != 0:
	if x > y:
		x = x % y
	else:
		y = y % x
print(min(a // (xx // (x + y)), b // (yy // (x + y))))


from math import gcd
(a, b, x, y) = map(int, input().split())
z = gcd(x, y)
(z1, z2) = (x // z, y // z)
print(min(a // z1, b // z2))


import math
(a, b, x, y) = map(int, input().split())
g = math.gcd(x, y)
x = x / g
y = y / g
if x <= a and y <= b:
	print(min(int(a / x), int(b / y)))
else:
	print(0)


def gcd(u, v):
	if u == v:
		return u
	elif u == 0:
		return v
	elif v == 0:
		return u
	elif u & 1 == 0:
		if v & 1 == 0:
			return 2 * gcd(u >> 1, v >> 1)
		else:
			return gcd(u >> 1, v)
	elif u & 1 != 0:
		if v & 1 == 0:
			return gcd(u, v >> 1)
		elif u > v and v & 1 != 0:
			return gcd(u - v >> 1, v)
		else:
			return gcd(v - u >> 1, u)
(a, b, x, y) = map(int, input().lstrip().split())
numx = gcd(x, y)
print(min(int(a / (x / numx)), int(b / (y / numx))))


import sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def inc(d, c):
	d[c] = d[c] + 1 if c in d else 1

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < n

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = 1
while t > 0:
	t -= 1
	(n, m, p, q) = mi()
	g = gcd(p, q)
	p //= g
	q //= g
	print(min(n // p, m // q))


def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
(a, b, x, y) = list(map(int, input().split()))
g = gcd(x, y)
x //= g
y //= g
print(min(a // x, b // y))


import math

def red(n, m):
	k = math.gcd(n, m)
	return (n // k, m // k)
(a, b, x, y) = map(int, input().split())
(x, y) = red(x, y)
i = 0
maxNA = a / x
maxNB = b / y
print(math.floor(min(maxNA, maxNB)))


def nod(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a
(w, h, x, y) = map(int, input().split())
n = nod(x, y)
x //= n
y //= n
if x >= y:
	ans = min((h - h % y) * x // y, w - w % x) // x
else:
	ans = min((w - w % x) * y // x, h - h % y) // y
print(ans)


def nod(a, b):
	a = int(a)
	b = int(b)
	if a > b:
		(a, b) = (b, a)
	if b % a == 0:
		return a
	else:
		while b != 0:
			if a > b:
				(a, b) = (b, a)
			x = b // a
			b -= x * a
		return a
s = input()
s = s.split()
a = int(s[0])
b = int(s[1])
x = int(s[2])
y = int(s[3])
q = nod(x, y)
x = x // q
y = y // q
if a > b:
	(a, b) = (b, a)
	(x, y) = (y, x)
i = a
i = min(b * x // y, a)
print(i // x)


(a, b, x, y) = list(map(int, input().split()))
(d, c) = sorted((x, y))
while d:
	(c, d) = (d, c % d)
x = x // c
y = y // c
res = min(a // x, b // y)
print(res)


import math
(a, b, x, y) = map(int, input().split())
z = math.gcd(x, y)
x /= z
y /= z
print(int(min(a / x, b / y) // 1))


import math
(a, b, x, y) = map(int, input().split())
e = math.gcd(x, y)
x = x // e
y = y // e
c = 0
if x > a or y > b:
	c = 0
else:
	q = a // x
	w = b // y
	c = min(q, w)
print(c)


import math
s = input().split()
a = int(s[0])
b = int(s[1])
x = int(s[2])
y = int(s[3])
g = math.gcd(x, y)
x //= g
y //= g
print(min(a // x, b // y))


def gcd(a, b):
	while b != 0:
		x = a % b
		a = b
		b = x
	return a
(a, b, x, y) = map(int, input().strip().split(' '))
d = gcd(x, y)
x1 = x // d
x2 = y // d
print(min(a // x1, b // x2))


import math as ma
(a, b, x, y) = map(int, input().split())
gg = ma.gcd(x, y)
x = x // gg
y = y // gg
pp = 0
pp = min(a // x, b // y)
print(pp)


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
(a, b, x, y) = map(int, input().split())
g = gcd(x, y)
x = x // g
y = y // g
a1 = a // x
b1 = b // y
print(min(a1, b1))


from math import gcd
(a, b, x, y) = [int(num) for num in input().split()]
g = gcd(x, y)
x = x // g
y = y // g
print(min(a // x, b // y))


a = input()
b = []
for i in range(len(a)):
	if a[i] == ' ':
		c = i
		b.append(c)
d = [a[:int(b[0])]]
for j in range(len(b) - 1):
	e = a[int(b[j]) + 1:int(b[j + 1])]
	d.append(e)
f = a[int(b[len(b) - 1]):]
d.append(f)
m = int(d[0])
n = int(d[1])
x = int(d[2])
y = int(d[3])

def hcfnaive(a, b):
	if b == 0:
		return a
	else:
		return hcfnaive(b, a % b)
h = hcfnaive(x, y)
t = x / h
u = y / h
v = n // u
w = m // t
if v * t / u <= m and w * u / t <= n:
	first = int(v)
	second = int(w)
	print(min(first, second))
elif v * t / u > m and w * u / t <= n:
	first = 0
	second = int(w)
	print(second)
elif v * t / u <= m and w * u / t > n:
	first = int(v)
	second = 0
	print(first)
else:
	first = second = 0
	print(first)


def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return abs(a)
(a, b, x, y) = (int(x) for x in input().split())
x1 = x
y1 = y
i = gcd(x, y)
x //= i
y //= i
print(min(a // x, b // y))


import time

def gcd(a, b):
	if a < b:
		(a, b) = (b, a)
	while b > 0:
		(a, b) = (b, a % b)
	return a
(a, b, x, y) = (int(i) for i in input().split())
start = time.time()
d = gcd(x, y)
x = x // d
y = y // d
ans = min(a // x, b // y)
print(ans)


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
(a, b, x, y) = [int(i) for i in input().split()]
(L, R) = (0, int(1e+20))
g = gcd(x, y)
x //= g
y //= g
while R - L > 1:
	M = (L + R) // 2
	w = M * x
	h = M * y
	if w <= a and h <= b:
		L = M
	else:
		R = M
print(L)


def hcf(a, b):
	if a == 1 or b == 1:
		return 1
	if a % b == 0:
		return b
	if b % a == 0:
		return a
	if a > b:
		return hcf(a % b, b)
	else:
		return hcf(b % a, a)

def lcm(a, b):
	return a * b // hcf(a, b)
(a, b, x, y) = map(int, input().split())

def tvset(a, b, x, y):
	lc = hcf(x, y)
	x = x // lc
	y = y // lc
	return int(min(a / x, b / y))
print(tvset(a, b, x, y))


import sys
input = sys.stdin.readline
from collections import *

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
(a, b, x, y) = map(int, input().split())
G = gcd(x, y)
x //= G
y //= G
print(min(a // x, b // y))


(a, b, x, y) = map(int, input().split())

def nod(a: int, b: int):
	r = a % b
	while r != 0:
		a = b
		b = r
		r = a % b
	return b
k = nod(x, y)
x = x // k
y = y // k
s = min(a // x, b // y)
print(s)


def GCD(a, b):
	while a != 0 and b != 0:
		(a, b) = (b % a, a)
	return max(a, b)
(a, b, x, y) = map(int, input().split())
f = GCD(x, y)
x //= f
y //= f
n = min(a, b * x // y)
print(n // x)


from collections import *
import sys
import math
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def li():
	return [int(i) for i in input().rstrip('\n').split(' ')]

def st():
	return input().rstrip('\n')

def val():
	return int(input())

def stli():
	return [int(i) for i in input().rstrip('\n')]
(a, b, c, d) = li()
while math.gcd(c, d) != 1:
	temp = math.gcd(c, d)
	c //= temp
	d //= temp
print(min(a // c, b // d))


def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
(a, b, x, y) = map(int, input().split())
i = gcd(y, x)
x = x // i
y = y // i
print(min(a // x, b // y))


(a, b, x, y) = map(int, input().split())

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
base = gcd(x, y)
x = x // base
y = y // base
wcount = a // x
hcount = b // y
print(min(wcount, hcount))


import math
(a, b, x, y) = map(int, input().split(' '))
gcd = math.gcd(x, y)
xx = x // gcd
yy = y // gcd
print(min(a // xx, b // yy))


def gcd(a, b):
	return a if b == 0 else gcd(b, a % b)

def main():
	(a, b, x, y) = map(int, input().split(' '))
	maxw = None
	maxh = None
	g = gcd(x, y)
	x //= g
	y //= g
	maxw = a - a % x
	maxh = b - b % y
	if maxw * y <= maxh * x:
		maxh = maxw * y // x
	else:
		maxw = maxh * x // y
	if maxw < x or maxh < y:
		print(0)
	else:
		print(int(min((maxw - x) // x + 1, (maxh - y) // y + 1)))
main()


from fractions import Fraction as F
ch = input().split()
a = int(ch[0])
b = int(ch[1])
e = int(ch[2])
f = int(ch[3])
ms = F(e, f).denominator
ts = F(e, f).numerator
e = int(a / ts)
f = int(b / ms)
print(min(e, f))


(a, b, x, y) = [int(x) for x in input().split()]

def gcd(u, v):
	if v == 0:
		return u
	else:
		return gcd(v, u % v)
g = gcd(x, y)
x = x // g
y = y // g
print(min(a // x, b // y))


(a, b, x, y) = [int(x) for x in input().split()]
m = x
n = y
count = 0
if m < n:
	(m, n) = (n, m)
while m % n != 0:
	(m, n) = (n, m % n)
x = x // n
y = y // n
count = min(a // x, b // y)
print(count)


def gcd(a, b):
	x = min(a, b)
	y = max(a, b)
	while x > 0:
		t = y
		y = x
		x = t % y
	return y
(a, b, x, y) = map(int, input().split())
k = gcd(x, y)
while k > 1:
	x //= k
	y //= k
	k = gcd(x, y)
print(min(a // x, b // y))


import math
from decimal import *
getcontext().prec = 30
(a, b, x, y) = map(int, input().split())
div = math.gcd(x, y)
(x, y) = (x // div, y // div)
print(min(a // x, b // y))


import math

def gcd(a, b):
	return gcd(b, a % b) if b else a
while True:
	try:
		(a, b, x, y) = map(int, input().strip().split())
		tp = gcd(x, y)
		x = x // tp
		y = y // tp
		print(min(a // x, b // y))
	except:
		break


s = input().split()
(a, b, x, y) = (int(s[0]), int(s[1]), int(s[2]), int(s[3]))
x1 = x
y1 = y
summ = 0
while x1 != y1:
	if max(x1, y1) % min(x1, y1) == 0:
		x1 = min(x1, y1)
		break
	(x1, y1) = (max(x1, y1) % min(x1, y1), min(x1, y1))
(x, y) = (x // x1, y // x1)
(a1, b1) = (a // x, b // y)
print(min(a1, b1))


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def buy(a, b, x, y):
	g = gcd(x, y)
	x //= g
	y //= g
	return min(a // x, b // y)
(A, B, X, Y) = [int(i) for i in input().split()]
print(buy(A, B, X, Y))


import math
(a, b, x, y) = list(map(int, input().split()))
g = math.gcd(x, y)
x = x // g
y = y // g
a1 = a // x
a2 = b // y
ans = min(a1, a2)
print(ans)


from fractions import Fraction
import math as maths
params = input()
(a, b, x, y) = (int(params.split(' ')[0]), int(params.split(' ')[1]), int(params.split(' ')[2]), int(params.split(' ')[3]))
if not x % y == 0:
	(xMin, yMin) = (int(str(Fraction(x, y)).split('/')[0]), int(str(Fraction(x, y)).split('/')[1]))
else:
	(xMin, yMin) = (x / y, 1)
options = []
options.append(a // xMin)
options.append(b // yMin)
print(int(min(options)))


import math
(a, b, x, y) = map(int, input().split())
if math.gcd(x, y) != 1:
	temp = math.gcd(x, y)
	x /= temp
	y /= temp
print(int(min(a // x, b // y)))


import fractions
(a, b, x, y) = map(int, input().split())
sf = fractions.Fraction(x, y)
print(min(a // sf.numerator, b // sf.denominator))


import sys
from bisect import bisect_left, bisect_right, insort
from collections import deque, Counter
from math import gcd, sqrt, factorial, ceil, log10, log2, floor
from itertools import permutations
from heapq import heappush, heappop, heapify
inf = float('inf')
mod = 998244353

def factorial_p(n, p):
	ans = 1
	if n <= p // 2:
		for i in range(1, n + 1):
			ans = ans * i % p
	else:
		for i in range(1, p - n):
			ans = ans * i % p
		ans = pow(ans, p - 2, p)
		if n % 2 == 0:
			ans = p - ans
	return ans

def nCr_p(n, r, p):
	ans = 1
	while n != 0 or r != 0:
		(a, b) = (n % p, r % p)
		if a < b:
			return 0
		ans = ans * factorial_p(a, p) * pow(factorial_p(b, p), p - 2, p) * pow(factorial_p(a - b, p), p - 2, p) % p
		n //= p
		r //= p
	return ans

def prime_sieve(n):
	flag = n % 6 == 2
	sieve = bytearray((n // 3 + flag >> 3) + 1)
	for i in range(1, int(n ** 0.5) // 3 + 1):
		if not sieve[i >> 3] >> (i & 7) & 1:
			k = 3 * i + 1 | 1
			for j in range(k * k // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
			for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
	return sieve

def prime_list(n):
	res = []
	if n > 1:
		res.append(2)
	if n > 2:
		res.append(3)
	if n > 4:
		sieve = prime_sieve(n + 1)
		res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
	return res

def is_prime(n):
	if n < 5 or n & 1 == 0 or n % 3 == 0:
		return 2 <= n <= 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			p = p * p % n
			if p == n - 1:
				break
		else:
			return False
	return True

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	large.reverse()
	small.extend(large)
	return small

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(a, b, x, y) = get_ints()
z = gcd(x, y)
x //= z
y //= z
print(min(a // x, b // y))


import math
(a, b, x, y) = map(int, input().split())
t = math.gcd(x, y)
x = x // t
y = y // t
h = min(y * a // x, b)
ans = h // y
print(ans)


def gcd(_first, _second):
	first = _first
	second = _second
	if first < second:
		(first, second) = (second, first)
	rem = -1
	while rem != 0:
		rem = first % second
		first = rem
		if first < second:
			(first, second) = (second, first)
	return first
(a, b, x, y) = map(int, input().split())
res = 0
t_gcd = gcd(x, y)
x = x / t_gcd
y = y / t_gcd
print(int(min(a // x, b // y)))


import math
(a, b, x, y) = map(int, input().split(' '))
gc = math.gcd(x, y)
x = int(x / gc)
y = int(y / gc)
count = 0
t = min(a // x, b // y)
print(t)


def evklid(a1, b1):
	while a1 != 0 and b1 != 0:
		if a1 > b1:
			a1 %= b1
		else:
			b1 %= a1
	return a1 + b1
(a, b, x, y) = map(int, input().split())
nod = evklid(x, y)
x //= nod
y //= nod
countX = a // x
countY = b // y
print(min(countX, countY))


def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
(a, b, x, y) = map(int, str(input()).strip().split())
while gcd(x, y) != 1:
	t = gcd(x, y)
	x //= t
	y //= t
r = a // x
p = b // y
print(min(r, p))


arr = list(map(int, input().split()))
a = arr[0]
b = arr[1]
x = arr[2]
y = arr[3]

def gcd(l, m):
	if l % m == 0:
		return m
	return gcd(m, l % m)
xygcd = gcd(max(x, y), min(x, y))
x = x // xygcd
y = y // xygcd
print(min(a // x, b // y))


import math
(a, b, x, y) = map(int, input().split())
sum = 0
o = math.gcd(x, y)
x = x / o
y = y / o
print(int(min(a // x, b // y)))


(a, b, x, y) = map(int, input().split())

def getNode(a, b):
	while a != 0 and b != 0:
		if a > b:
			a = a % b
		else:
			b = b % a
	return a + b
nod = getNode(x, y)
x = int(x / nod)
y = int(y / nod)
k1 = int(a / x)
k2 = int(b / y)
res = min(k1, k2)
print(res)


def find_gcd(a, b):
	while b != 0:
		r = a % b
		a = b
		b = r
	return a
(a, b, x, y) = map(int, input().split())
gcd = find_gcd(x, y)
start_w = x / gcd
start_h = y / gcd
max_mult = min(a // start_w, b // start_h)
print(int(max_mult))


(a, b, x, y) = map(int, input().split())

def gcd(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a
u = x // gcd(x, y)
v = y // gcd(x, y)
ans = min(a // u, b // v)
print(ans)


(a, b, x, y) = map(int, input().split())

def gcd(s, t):
	while t > 0:
		(s, t) = (t, s % t)
	return s
k = gcd(x, y)
x1 = x / k
y1 = y / k
p1 = int(a / x1)
p2 = int(b / y1)
print(min(p1, p2))


def gcd(x, y):
	if x < y:
		minm = x
		maxm = y
	else:
		minm = y
		maxm = x
	if maxm % minm == 0:
		return minm
	return gcd(minm, maxm % minm)
(a, b, x, y) = input().split()
a = int(a)
b = int(b)
x = int(x)
y = int(y)
g = gcd(x, y)
x = x // g
y = y // g
ans = min(a // x, b // y)
print(ans)


def fun(a, b, x, y):
	gcd = bmm(x, y)
	x = x / gcd
	y = y / gcd
	aa = int(a / x)
	ab = int(b / y)
	if aa > ab:
		return ab
	else:
		return aa

def bmm(x, y):
	r = x % y
	if r == 0:
		return y
	else:
		return bmm(y, r)
(a, b, c, d) = map(int, input().split())
print(fun(a, b, c, d))


t = list(map(int, input().split(' ')))

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
a = t[0]
b = t[1]
x = t[2]
y = t[3]
g = gcd(x, y)
x //= g
y //= g
ans = 0
h_max = min(b, a * y // x)
w_max = min(a, b * x // y)
ans = min(h_max // y, w_max // x)
print(ans)


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
(m, n, o, p) = map(int, input().split(' '))
great = gcd(o, p)
o /= great
p /= great
print(min(int(m / o), int(n / p)))


import math
(a, b, x, y) = map(int, input().strip().split())

def gcd(a, b):
	if b == 0:
		return a
	if a < b:
		return gcd(b, a)
	return gcd(b, a % b)
g = gcd(x, y)
x = int(x / g)
y = int(y / g)
if a * y <= b * x:
	print(int(a / x))
else:
	print(int(b / y))


from sys import stdin, stdout
from math import gcd
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	(a, b, x, y) = lst()
	g = gcd(x, y)
	x //= g
	y //= g
	print(min(a // x, b // y))


line = list(map(int, input().split()))
a = line[0]
b = line[1]
x = line[2]
y = line[3]

def gcd(a, b):
	while a != 0 and b != 0:
		if a > b:
			a %= b
		else:
			b %= a
	return a + b
j = gcd(x, y)
x //= j
y //= j
n = 0
k1 = a // x
k2 = b // y
n = min(k1, k2)
print(n)


import math
(a, b, x, y) = input().split()
(a, b, x, y) = [int(a), int(b), int(x), int(y)]
g = math.gcd(x, y)
x = x // g
y = y // g
w = a // x
h = b // y
print(min(w, h))


from fractions import Fraction
(a, b, x, y) = map(int, input().split())
u = Fraction(x, y).numerator
v = Fraction(x, y).denominator
d = a // u
e = b // v
print(min(d, e))


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
(a, b, c, d) = map(int, input().split())
fpb = gcd(c, d)
c = c // fpb
d = d // fpb
print(min(a // c, b // d))


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	(a, b, x, y) = map(int, input().split())
	z = 0
	count = 0
	temp = GCD(x, y)
	x = x // temp
	y = y // temp
	print(min(a // x, b // y))
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
import math
(a, b, x, y) = read_ints()
gcd = math.gcd(x, y)
print(min(a // (x // gcd), b // (y // gcd)))


def cin(obj=list, type=int, sep=' '):
	return obj(map(type, input().split(sep)))
(a, b, x, y) = cin()

def gcd(a, b):
	while b:
		a %= b
		(a, b) = (b, a)
	return a
g = gcd(x, y)
x //= g
y //= g
print(min(a // x, b // y))


def gcd(a, b):
	if a < b:
		(a, b) = (b, a)
	if b == 0:
		return a
	return gcd(b, a % b)
(a, b, x, y) = map(int, input().split())
gcd_xy = gcd(x, y)
if gcd_xy > 1:
	x = x // gcd_xy
	y = y // gcd_xy
print(min(a // x, b // y))


import math
abxy = [int(asdf) for asdf in input().split()]
a = abxy[0]
b = abxy[1]
x = abxy[2]
y = abxy[3]
div = math.gcd(x, y)
x /= div
y /= div
print(int(min(a // x, b // y)))


import math
(a, b, x, y) = [int(x) for x in input().split()]
g = math.gcd(x, y)
x //= g
y //= g
mina = min(a // x, b // y)
print(mina)


from math import gcd
from functools import reduce
(h, w, x, y) = map(int, input().split())
a = str(x) + ':' + str(y)

def solve(ratio):
	numbers = [int(i) for i in ratio.split(':')]
	denominater = reduce(gcd, numbers)
	solved = [i / denominater for i in numbers]
	return ':'.join((str(int(i)) for i in solved))
a = solve(a)
(x, y) = map(int, a.split(':'))
print(min(h // x, w // y))


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = 1
for tt in range(t):
	(a, b, x, y) = map(int, sys.stdin.readline().split(' '))
	g = math.gcd(x, y)
	x = x // g
	y = y // g
	print(min(a // x, b // y))
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
li = lambda : list(map(int, input().split()))

def solve():
	(a, b, x, y) = li()
	g = math.gcd(x, y)
	p = x // g
	q = y // g
	print(min(a // p, b // q))
for _ in range(1):
	solve()


def NOD(a, b):
	if a == 0:
		return b
	else:
		return NOD(b % a, a)
arr = list(input().split(' '))
(a, b, x, y) = (int(arr[0]), int(arr[1]), int(arr[2]), int(arr[3]))
res = 0
(cur_x, cur_y) = (x, y)
rel = x / y
nod = NOD(x, y)
cur_x = x // nod
cur_y = y // nod
res = min(a // cur_x, b // cur_y)
print(res)


__author__ = 'Esfandiar'
import sys
from math import gcd
input = sys.stdin.readline
(a, b, x, y) = map(int, input().split())
while True:
	t = gcd(x, y)
	if t == 1:
		break
	x //= t
	y //= t
print(min(a // x, b // y))


import sys
import math as mt
import bisect
input = sys.stdin.readline
t = 1
for _ in range(t):
	(a, b, x, y) = map(int, input().split())
	g = mt.gcd(x, y)
	x //= g
	y //= g
	print(min(a // x, b // y))


import math
(a, b, x, y) = map(int, input().split())
g = math.gcd(x, y)
x = x / g
y = y / g
maxx = a // x
maxy = b // y
print(int(min(maxx, maxy)))


from fractions import Fraction
params = input()
(a, b, x, y) = (int(params.split(' ')[0]), int(params.split(' ')[1]), int(params.split(' ')[2]), int(params.split(' ')[3]))
if not x % y == 0:
	(xMin, yMin) = (int(str(Fraction(x, y)).split('/')[0]), int(str(Fraction(x, y)).split('/')[1]))
else:
	(xMin, yMin) = (int(x / y), 1)
print(min(a // xMin, b // yMin))


def gcd(a, b):
	if a % b == 0:
		return b
	return gcd(b, a % b)
from math import log2
(a, b, x, y) = map(int, input().split())
k = gcd(x, y)
x = x // k
y = y // k
print(min(a // x, b // y))


(a, b, x, y) = map(int, input().split())

def gcd(x, y):
	while x != 0 and y != 0:
		if x >= y:
			x = x % y
		elif y > x:
			y = y % x
	return x + y
f = gcd(x, y)
x /= f
y /= f
ans = int(min(a // x, b // y))
print(ans)


from math import gcd
a = list(map(int, input().split()))
l = gcd(a[2], a[3])
a[2] = a[2] // l
a[3] = a[3] // l
print(min(a[0] // a[2], a[1] // a[3]))


s = input()
lis = s.split(' ')

def hcf(a, b):
	if a % b == 0:
		return b
	else:
		return hcf(b, a % b)
k = hcf(int(lis[2]), int(lis[3]))
a = int(int(lis[0]) // (int(lis[2]) / k))
b = int(int(lis[1]) // (int(lis[3]) / k))
print(min(a, b))


import math

def mi():
	return map(int, input().split(' '))
(x, y, a, b) = mi()
ans = 0
g = math.gcd(a, b)
a = a // g
b = b // g
ia = x // a
ib = y // b
ans = min(ia, ib)
print(ans)


def gcd(a, b):
	x = max(a, b)
	y = min(a, b)
	while True:
		z = x % y
		if z == 0:
			return y
		x = y
		y = z
(a, b, x, y) = map(int, input().split())
z = gcd(x, y)
x /= z
y /= z
h = int(a / x)
w = int(b / y)
print(min(h, w))


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def findSmallest(a, b):
	lcm = a * b / gcd(a, b)
	return (lcm / a, lcm / b)
(a, b, x, y) = map(int, input().split())
(y, x) = findSmallest(x, y)
print(min(int(a / x), int(b / y)))


def HOD(a, b):
	while b > 0:
		(a, b) = (b, a % b)
	return a
(a, b, x, y) = map(int, input().split())
d = HOD(x, y)
x //= d
y //= d
maxw = a // x * x
maxw1 = a // x * y
maxh = b // y * y
maxh1 = b // y * x
if maxw1 <= b:
	print(a // x)
else:
	print(b // y)


from math import gcd

def main():
	(a, b, x, y) = map(int, input().split())
	g = gcd(x, y)
	x //= g
	y //= g
	print(min(a // x, b // y))
main()


import math
(a, b, x, y) = input().split()
a = int(a)
b = int(b)
x = int(x)
y = int(y)
p = math.gcd(x, y)
x = x // p
y = y // p
maxidiv = b // y * y
low = int(1)
high = int(maxidiv // y)
while low <= high:
	mid = (low + high) // 2
	if x * mid <= a:
		low = mid + 1
	else:
		high = mid - 1
print(low - 1)


import math
(a, b, x, y) = map(int, input().split())
int_val = math.gcd(x, y)
x //= int_val
y //= int_val
r1 = a // x
r2 = b // y
if r1 < r2:
	print(r1)
else:
	print(r2)


import math
(a, b, x, y) = (int(x) for x in input().split())
gcd = math.gcd(x, y)
x //= gcd
y //= gcd
wm = a // x
hm = b // y
ans = min(wm, hm)
print(ans)


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
(a, b, x, y) = map(int, input().split())
g = gcd(x, y)
x = x // g
y = y // g
i = a // x
j = b // y
print(min(i, j))


import sys
from fractions import Fraction
(a, b, x, y) = list(map(int, sys.stdin.readline().strip().split()))
f = str(Fraction(x, y)).split('/')
if len(f) == 1:
	x = int(f[0])
	y = 1
else:
	x = int(f[0])
	y = int(f[1])
print(min(int(a / x), int(b / y)))


(a, b, x, y) = list(map(int, input().split()))
(x1, y1) = (x, y)
while y1 != 0:
	(x1, y1) = (y1, x1 % y1)
x = x // x1
y = y // x1
print(min(a // x, b // y))


def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
(a, b, x, y) = [int(x) for x in input().split()]
g = gcd(x, y)
x = x / g
y = y / g
ans = min(a / x, b / y)
print(int(ans))


import math

class CodeforcesTask1041BSolution:

	def __init__(self):
		self.result = ''
		self.a_b_x_y = []

	def read_input(self):
		self.a_b_x_y = [int(x) for x in input().split(' ')]

	def process_task(self):
		f = int(math.gcd(self.a_b_x_y[2], self.a_b_x_y[3]))
		dw = self.a_b_x_y[3] // f
		dh = self.a_b_x_y[2] // f
		valid_widths = self.a_b_x_y[0] // dh
		valid_heights = self.a_b_x_y[1] // dw
		self.result = str(min(valid_heights, valid_widths))

	def get_result(self):
		return self.result
Solution = CodeforcesTask1041BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


import math
(a, b, x, y) = [int(i) for i in input().split()]
i = 1
l = math.gcd(x, y)
x = x // l
y = y // l
m = a // x
p = b // y
i = min(m, p)
print(i)


def gcd(a, b):
	x = max(a, b)
	y = min(a, b)
	while x != 0 and y != 0:
		x = x % y
		if x == 0:
			break
		y = y % x
	return max(x, y)
(a, b, x, y) = map(int, input().split())
h = gcd(x, y)

def gcd(a, b):
	x = max(a, b)
	y = min(a, b)
	while x != 0 and y != 0:
		x = x % y
		if x == 0:
			break
		y = y % x
	return max(x, y)
x //= h
y //= h
if a / x < b / y:
	print(a // x)
else:
	print(b // y)


def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
(a, b, x, y) = map(int, input().split())
d = gcd(x, y)
A = x // d
B = y // d
k2 = a // A
k1 = b // B
print(min(k1, k2))


USE_STDIO = False
if not USE_STDIO:
	try:
		import mypc
	except:
		pass

def gcd(x, y):
	if x % y == 0:
		return y
	return gcd(y, x % y)

def main():
	(a, b, x, y) = list(map(int, input().split(' ')))
	g = gcd(x, y)
	(x, y) = (x // g, y // g)
	ans = min(a // x, b // y)
	print(ans)

def __starting_point():
	main()
__starting_point()


def Check(a, b):
	while b != 0:
		c = a % b
		a = b
		b = c
	return a
b = list(map(int, input().split()))
c = Check(b[2], b[3])
print(int(min(b[0] / (b[2] / c), b[1] / (b[3] / c))))


import math
[a, b, x, y] = map(int, input().split())
gcd = math.gcd(x, y)
minX = x / gcd
minY = y / gcd
counta = int(a // minX)
countb = int(b // minY)
print(min(counta, countb))


def gdc(a, b):
	return a % b == 0 and b or gdc(b, a % b)
(a, b, x, y) = map(int, input().split())
z = gdc(x, y)
x /= z
y /= z
print(int(min(a // x, b // y)))


(a, b, x, y) = tuple(map(int, input().split()))
if x < y:
	(a, b, x, y) = (b, a, y, x)

def GCD(a, b):
	if b == 0:
		return a
	else:
		return GCD(b, a % b)
gcd = GCD(x, y)
x = x // gcd
y = y // gcd
print(min(a // x, b // y))


from fractions import Fraction
(a, b, x, y) = map(int, input().split())
s = str(Fraction(x, y))
(n, i) = (len(s), 0)
while i < n and s[i] != '/':
	i += 1
if i == n:
	(x, y) = (int(s), 1)
else:
	(x, y) = (int(s[:i]), int(s[i + 1:]))
print(min(int(a // x), int(b // y)))


import math
string = input().split()
a = int(string[0])
b = int(string[1])
x = int(string[2])
y = int(string[3])
res = 0
k = math.gcd(x, y)
x = x // k
y = y // k
res = min(a // x, b // y)
print(res)


from fractions import Fraction as f
(a, b, x, y) = list(map(int, input().split()))
n = f(x, y)
x = n.numerator
y = n.denominator
print(min(a // x, b // y))


import math as m
(a, b, x, y) = map(int, input().split())
g = m.gcd(x, y)
x //= g
y //= g
print(min(a // x, b // y))


gcd = lambda a, b: gcd(b, a % b) if b else a
(a, b, x, y) = map(int, input().split())
g = gcd(x, y)
print(min(a // (x // g), b // (y // g)))


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	(a, b, x, y) = map(int, input().split(' '))
	temp = math.gcd(x, y)
	x = x // temp
	y = y // temp
	print(min(a // x, b // y))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(a, b, x, y) = map(int, input().split())

def nod(i, j):
	if j == 0:
		return i
	return nod(j, i % j)
k = nod(x, y)
x //= k
y //= k
va = a // x
vb = b // y
print(min(va, vb))


(a, b, x, y) = [int(n) for n in input().split()]

def computeGCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
k = computeGCD(x, y)
x //= k
y //= k
print(min(a // x, b // y))


import math
R = input
(a, b, x, y) = map(int, R().split())
g = math.gcd(x, y)
x = x / g
y = y / g
print(min(math.floor(a / x), math.floor(b / y)))


def NOD(x, y):
	while x != 0 and y != 0:
		if x > y:
			x %= y
		else:
			y %= x
	gcd = x + y
	return gcd
(a, b, x, y) = [int(x) for x in input().split()]
if NOD(x, y) != 1:
	(w, h) = (x / NOD(x, y), y / NOD(x, y))
else:
	(w, h) = (x, y)
max_a = int(a // w)
max_b = int(b // h)
if max_a < max_b:
	print(max_a)
elif max_b < max_a:
	print(max_b)
elif max_b == max_a:
	print(max_a)


def gcd(a, b):
	while b:
		c = a % b
		a = b
		b = c
	return a

def check(l, r, x):
	return l <= x and x <= r
(a, b, x, y) = map(int, input().split())
g = gcd(x, y)
w0 = x // g
y0 = y // g
if not check(1, a, w0) or not check(1, b, y0):
	print(0)
else:
	l = 1
	r = max((a + w0 - 1) // w0, (b + y0 - 1) // y0) + 1
	while r - l > 1:
		m = l + (r - l) // 2
		if not check(1, a, m * w0) or not check(1, b, m * y0):
			r = m
		else:
			l = m
	print(l)


from sys import stdin, stdout
import cProfile
printHeap = str()
test = False
memory_constrained = False

def display(string_to_print):
	stdout.write(str(string_to_print) + '\n')

def test_print(output):
	if test:
		stdout.write(str(output) + '\n')

def display_list(list1, sep=' '):
	stdout.write(sep.join(map(str, list1)) + '\n')

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))
memory = dict()

def clear_cache():
	global memory
	memory = dict()

def cached_fn(fn, *args):
	global memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result
import math

def main():
	(a, b, x, y) = get_tuple()
	gcd = math.gcd(x, y)
	(x, y) = (x // gcd, y // gcd)
	display(min(a // x, b // y))
cProfile.run('main()') if test else main()


def NOD(a, b):
	if a % b == 0:
		return b
	else:
		while a % b != 0:
			r = a
			a = b
			b = r % a
		return b
s = input().split()
a = int(s[0])
b = int(s[1])
x = int(s[2])
y = int(s[3])
nd = NOD(x, y)
if nd == 1:
	print(min(a // x, b // y))
else:
	print(min(a // (x // nd), b // (y // nd)))


import math

def gcd(a, b):
	(a, b) = (max(a, b), min(a, b))
	while a % b != 0:
		(a, b) = (b, a % b)
	return b
(a, b, x, y) = map(int, input().split())
k = gcd(x, y)
x //= k
y //= k
print(min(a // x, b // y))


import math
arr = [int(s) for s in input().split()]
a = arr[0]
b = arr[1]
x = arr[2]
y = arr[3]
g = math.gcd(x, y)
x /= g
y /= g
w = int(a // x)
h = int(b // y)
if w > h:
	print(h)
else:
	print(w)


from math import gcd
(a, b, x, y) = map(int, input().strip().split())
cm = gcd(x, y)
x = x // cm
y = y // cm
print(min(a // x, b // y))


def gcd(a, b):
	if a % b == 0:
		return b
	return gcd(b, a % b)
(a, b, x, y) = map(int, input().split())
g = gcd(x, y)
x = x // g
y = y // g

def check(k):
	return x * k <= a and k * y <= b

def BinarySearch(low, high):
	res = high
	while low <= high:
		mid = (low + high) // 2
		if check(mid):
			res = mid
			low = mid + 1
		else:
			high = mid - 1
	return res
print(BinarySearch(0, max(a, b) + 5))


def nod(a, b):
	if b == 0:
		return a
	return nod(b, a % b)
[a, b, x, y] = [int(i) for i in input().split()]
n = nod(x, y)
x /= n
y /= n
print(int(min(a // x, b // y)))


def computeGCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
(a, b, x, y) = map(int, input().split())
z = computeGCD(x, y)
x = x / z
y = y / z
a = a // x
b = b // y
print(int(min(a, b)))


def gcd(x, y):
	return x if y == 0 else gcd(y, x % y)
(a, b, x, y) = map(int, input().split())
val = gcd(x, y)
x //= val
y //= val
a_min = a // x
b_min = b // y
print(min(a_min, b_min))


def gcd(a, b, res):
	if a == b:
		return a * res
	elif a % 2 == 0 and b % 2 == 0:
		return gcd(a // 2, b // 2, 2 * res)
	elif a % 2 == 0:
		return gcd(a // 2, b, res)
	elif b % 2 == 0:
		return gcd(a, b // 2, res)
	elif a > b:
		return gcd(a - b, b, res)
	elif a < b:
		return gcd(a, b - a, res)
(a, b, x, y) = map(int, input().rstrip().split(' '))
z = gcd(x, y, 1)
x = x // z
y = y // z
possibleVariants = min(a // x, b // y)
print(possibleVariants)


import math
r = [int(x) for x in input().split()]
a = int(r[0])
b = int(r[1])
x = int(r[2])
y = int(r[3])
z = math.gcd(x, y)
x = int(x / z)
y = int(y / z)
ans = 0
if x > a | y > b:
	ans = 0
else:
	ans = min(int(a / x), int(b / y))
print(ans)


import heapq as hq
import math
(a, b, x, y) = [int(i) for i in input().split(' ')]
g = math.gcd(x, y)
x /= g
y /= g
print(int(min(a // x, b // y)))


import math as m
(a, b, x, y) = [int(x) for x in input().split()]
k = m.gcd(x, y)
xn = x // k
yn = y // k
print(min(a // xn, b // yn))


import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import List
sys.setrecursionlimit(99999)
(a, b, x, y) = map(int, input().split())
g = math.gcd(x, y)
x //= g
y //= g
print(min(a // x, b // y))


def gcd(a, b):
	x = min(a, b)
	y = max(a, b)
	while y:
		(x, y) = (y, x % y)
	return x
n = input()
n = n.split()
a = int(n[0])
b = int(n[1])
x = int(n[2])
y = int(n[3])
i = gcd(x, y)
x = x // i
y = y // i
l = a // x
m = b // y
print(min(l, m))


c = list(map(int, input().split()))
a = c[0]
b = c[1]
x = c[2]
y = c[3]

def gcd(x, y):
	if y == 0:
		return x
	return gcd(y, x % y)
t = gcd(x, y)
x = x / t
y = y / t
print(min(int(a / x), int(b / y)))


from math import gcd
[a, b, x, y] = [int(i) for i in input().split()]
g = gcd(x, y)
x //= g
y //= g
a_num = a // x
b_num = b // y
print(min(a_num, b_num))


def evklid(a, b):
	if a % b == 0:
		return b
	else:
		return evklid(b, a % b)
(a, b, c, d) = map(int, input().split())
r = evklid(c, d)
c //= r
d //= r
m = min(a // c, b // d)
print(m)


import math
import bisect
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))

def mex(arr):
	nList = set(arr)
	mex = 0
	while mex in nList:
		mex += 1
	return mex

def results(arr):
	(a, b, x, y) = (arr[0], arr[1], arr[2], arr[3])
	g = gcd(x, y)
	(w, h) = (x // g, y // g)
	return min(a // w, b // h)

def main():
	a = seq()
	result = results(a)
	print(result)
main()


from sys import stdin, stdout

def gcd(a, b):
	if not b:
		return a
	else:
		return gcd(b, a % b)
(a, b, x, y) = map(int, stdin.readline().split())
g = gcd(x, y)
x //= g
y //= g
(l, r) = (0, 10 ** 18 + 1)
while r - l > 1:
	m = l + r >> 1
	if m * x <= a and m * y <= b:
		l = m
	else:
		r = m
stdout.write(str(l))


def NWD(a, b):
	if b == 0:
		return a
	return NWD(b, a % b)
(a, b, x, y) = map(int, input().split())
d = NWD(x, y)
x //= d
y //= d
print(min(a // x, b // y))


import math

def solve(a, b, x, y):
	val = math.gcd(x, y)
	x = x // val
	y = y // val
	res = 1
	key1 = a // x
	key2 = b // y
	return min(key1, key2)
while True:
	try:
		(a, b, x, y) = map(int, input().split())
		print(solve(a, b, x, y))
	except:
		break


(a, b, x, y) = map(int, input().split())

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def simplify_fraction(numer, denom):
	common_divisor = gcd(numer, denom)
	(reduced_num, reduced_den) = (numer / common_divisor, denom / common_divisor)
	if common_divisor == 1:
		return [numer, denom]
	else:
		return [reduced_num, reduced_den]
simplified = simplify_fraction(x, y)
print(int(min(a // simplified[0], b // simplified[1])))


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
(a, b, x, y) = map(int, input().split())
num = x // gcd(x, y)
den = y // gcd(x, y)
ans = min(a // num, b // den)
print(ans)


(a, b, x, y) = map(int, input().split())
xs = max(x, y)
ys = min(y, x)
while ys > 0:
	(xs, ys) = (ys, xs % ys)
x = x // xs
y = y // xs
if x == y:
	print(min(a, b))
else:
	print(min(a // x, b // y))


from math import gcd
(a, b, x, y) = [int(i) for i in input().split()]
while True:
	g = gcd(x, y)
	if g > 1:
		x //= g
		y //= g
	else:
		break
print(min(a // x, b // y))


def hcf(a, b):
	if b == 0:
		return a
	return hcf(b, a % b)
(a, b, x, y) = list(map(int, input().split()))
k = hcf(x, y)
(x, y) = (x // k, y // k)
print(min(a // x, b // y))


from fractions import *
a = input()
a = list(map(int, a.split()))
x = Fraction(a[2], a[3])
a[2] = x.numerator
a[3] = x.denominator
print(min(int(a[0] / a[2]), int(a[1] / a[3])))


import math
(a, b, x, y) = input().split()
a = int(a)
b = int(b)
x = int(x)
y = int(y)
nod = math.gcd(x, y)
x = x // nod
y = y // nod
print(min(a // x, b // y))


def gcd(a, b):
	while True:
		r = a % b
		if r == 0:
			return b
		a = b
		b = r
(a, b, x, y) = list(map(int, input().split()))
g = gcd(x, y)
(x, y) = (x / g, y / g)
print(int(min(a // x, b // y)))


def gcd(x, y):
	if x < y:
		return gcd(y, x)
	if y == 0:
		return x
	return gcd(y, x % y)
(a, b, x, y) = map(int, input().split())
r = gcd(x, y)
x = int(x / r)
y = int(y / r)
print(min(int(a / x), int(b / y)))


from math import gcd

def sol(a, b, x, y):
	return min(int(a / x), int(b // y))
(a, b, x, y) = [int(i) for i in input().split()]
g = gcd(x, y)
x /= g
y /= g
print(sol(a, b, x, y))


import sys

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans
mod = int(1000000000.0) + 7

def ssinp():
	return sys.stdin.readline().strip()

def iinp():
	return int(input())

def nninp():
	return map(int, sys.stdin.readline().strip().split())

def llinp():
	return list(map(int, sys.stdin.readline().strip().split()))

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
import math
from collections import OrderedDict
from fractions import Fraction
(a, b, x, y) = nninp()
d = math.gcd(x, y)
x = x // d
y = y // d
print(min(a // x, b // y))


def gcd(a, b):
	if a < b:
		(a, b) = (b, a)
	if b == 0:
		return a
	return gcd(b, a % b)

def f(ll):
	(a, b, x, y) = ll
	g = gcd(x, y)
	x = x // g
	y = y // g
	return min(a // x, b // y)
l = list(map(int, input().split()))
print(f(l))


def compute_hcf(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
(a, b, x, y) = map(int, input().split())
i = 2
c = compute_hcf(x, y)
(x, y) = (x // c, y // c)
print(min(a // x, b // y))


import math
(a, b, x, y) = map(int, input().split())
t = math.gcd(x, y)
nx = x / t
ny = y / t
maxa = a // nx
maxb = b // ny
print(int(min(maxa, maxb)))


from math import gcd
(a, b, x, y) = list(map(int, input().split()))
g = gcd(x, y)
x //= g
y //= g
w = a // x
h = b // y
print(min(w, h))


def gcd(x, y):
	if x * y == 0:
		return x + y
	return gcd(y, x % y)
(a, b, x, y) = map(int, input().split())
temp = x
x //= gcd(x, y)
y //= gcd(y, temp)
check = min(a, b * x // y)
print(int(check // x))


from math import gcd
m = list(map(int, input().split()))
a = m[0]
b = m[1]
x = m[2]
y = m[3]
d = gcd(x, y)
x = x // d
y = y // d
x = a // x
y = b // y
if x < y:
	print(x)
else:
	print(y)


def uscln(u, v):
	if u == v:
		return u
	elif u == 0:
		return v
	elif v == 0:
		return u
	elif u & 1 == 0:
		if v & 1 == 0:
			return 2 * uscln(u >> 1, v >> 1)
		else:
			return uscln(u >> 1, v)
	elif u & 1 != 0:
		if v & 1 == 0:
			return uscln(u, v >> 1)
		elif u > v and v & 1 != 0:
			return uscln(u - v >> 1, v)
		else:
			return uscln(v - u >> 1, u)
[a, b, x, y] = list(map(int, input(' ').split(' ')))
temp = uscln(x, y)
print(int(min(a / (x / temp), b / (y / temp))))


import sys
from math import gcd

def rint():
	return map(int, sys.stdin.readline().split())
(a, b, x, y) = rint()
div = gcd(x, y)
x = x // div
y = y // div
aa = a // x
bb = b // y
print(min(aa, bb))


(a, b, x, y) = map(int, input().split())

def gcd(n1, n2):
	if n2 > n1:
		return gcd(n2, n1)
	if n2 == 0:
		return n1
	times = n1 // n2
	return gcd(n1 - times * n2, n2)
div = gcd(x, y)
x //= div
y //= div
amt1 = a // x
amt2 = b // y
print(min(amt1, amt2))


def gcd(a, b):
	if a == 0:
		return b
	else:
		return gcd(b % a, a)
(max_w, max_h, w, h) = map(int, input().split())
g = gcd(w, h)
w /= g
h /= g
ans = min(max_w // w, max_h // h)
print(int(ans))


from math import gcd
(a, b, x, y) = list(map(int, input().split()))
mcm = gcd(x, y)
simple_x = x // mcm
simple_y = y // mcm
print(min(a // simple_x, b // simple_y))


import functools
import time
from collections import Counter

def timer(func):

	@functools.wraps(func)
	def wrapper(*args, **kwargs):
		stime = time.perf_counter()
		res = func(*args, **kwargs)
		elapsed = time.perf_counter() - stime
		print(f'{func.__name__} in {elapsed:.4f} secs')
		return res
	return wrapper

class solver:

	def __init__(self):
		pass

	def __call__(self):

		def gcd(x, y):
			if x < y:
				(x, y) = (y, x)
			return x if y == 0 else gcd(y, x % y)
		(a, b, x, y) = map(int, input().strip().split())
		g = gcd(x, y)
		x //= g
		y //= g
		kx = a // x
		ky = b // y
		print(min(kx, ky))
solver()()


from math import gcd
(a, b, x, y) = [int(i) for i in input().split()]
c = gcd(x, y)
x //= c
y //= c
print(min(a // x, b // y))


import math
(a, b, x, y) = map(int, input().split())
(i, j, e, f) = (0, 0, 0, 0)
c = x
d = y
c = x // math.gcd(x, y)
d = y // math.gcd(x, y)
print(int(min(a / c, b / d)))


def gcd(a, b):
	while a != 0 and b != 0:
		if a > b:
			a = a % b
		else:
			b = b % a
	return a + b
values = (int(x) for x in input().split(' '))
(a, b, x, y) = values
divisor = gcd(x, y)
x /= divisor
y /= divisor
print(int(min(a // x, b // y)))


(a, b, x, y) = list(map(int, input().rsplit()))

def gdc(a, b):
	if b == 0:
		return a
	return gdc(b, a % b)
g = gdc(x, y)
x //= g
y //= g
print(min(a // x, b // y))


import sys
array = input().split(' ')
(a, b, x, y) = (int(array[0]), int(array[1]), int(array[2]), int(array[3]))

def pgcd(a, b):
	while b != 0:
		r = a % b
		(a, b) = (b, r)
	return a
p = pgcd(x, y)
k1 = a // (x / p)
k2 = b // (y / p)
if k1 < k2:
	print(int(k1))
else:
	print(int(k2))


def cin(obj=list, type=int, sep=' '):
	return obj(map(type, input().split(sep)))
(a, b, x, y) = cin()
from math import gcd
g = gcd(x, y)
x //= g
y //= g
print(min(a // x, b // y))


import math

def euclidus(a, b):
	if b == 0:
		return a
	return euclidus(b, a % b)

def counter(a, b, x, y):
	D = euclidus(x, y)
	x = int(x / D)
	y = int(y / D)
	print(min(a // x, b // y))

def main():
	(w, h, x, y) = [int(s) for s in input().split()]
	counter(w, h, x, y)
main()


(a, b, x, y) = list(map(int, input().split()))

def gcd(a, b):
	if a == 0 or b == 0:
		return a + b
	return gcd(b, a % b)
d = gcd(x, y)
x = x / d
y = y / d
print(int(min(a / x, b / y)))


import math
numbers = input()
num_list = [int(x) for x in numbers.split(' ')]
gcd_num = math.gcd(num_list[2], num_list[3])
x = num_list[2] // gcd_num
y = num_list[3] // gcd_num
a = num_list[0]
b = num_list[1]
list_gcd = []
k = 1
m = x
n = y
i = min(a // x, b // y)
print(i)


from math import gcd
(a, b, c, d) = list(map(int, input().split()))
print(min(a // (c // gcd(c, d)), b // (d // gcd(c, d))))


def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
(a, b, x, y) = [int(i) for i in input().split()]
z = gcd(x, y)
print(min(a // (x // z), b // (y // z)))


def euler(a, b: int) -> int:
	(a, b) = (a, b) if a > b else (b, a)
	while a > 0 and b > 0:
		(a, b) = (b, a % b)
	return a
(ma, mb, sx, sy) = (int(a) for a in input().split())
gd = euler(sx, sy)
(sx, sy) = (sx // gd, sy // gd)
(res_x, res_y) = (ma // sx, mb // sy)
print(res_x if res_x < res_y else res_y)


(a, b, x, y) = map(int, input().split())
g = __import__('math').gcd(x, y)
x //= g
y //= g
print(min(a // x, b // y))


import sys

def main():
	(a, b, x, y) = [int(x) for x in sys.stdin.read().split()]
	n = nsd(x, y)
	w = x // n
	h = y // n
	count = min(a // w, b // h)
	print(count)

def nsd(a, b):
	x = a // b
	y = a % b
	if y == 0:
		return b
	else:
		return nsd(b, y)
main()


import sys
import math
f = sys.stdin
out = sys.stdout
(a, b, x, y) = map(int, f.readline().rstrip('\r\n').split())
g = math.gcd(x, y)
x = x // g
y = y // g
n1 = a // x
n2 = b // y
out.write(str(min(n1, n2)))


from math import sqrt
(a, b, x, y) = list(map(int, input().split()))

def gcd(a, b):
	while b > 0:
		(a, b) = (b, a % b)
	return a
count = 1
gcd_xy = gcd(x, y)
total = min(a // (x / gcd_xy), b // (y / gcd_xy))
print(int(min(a // (x / gcd_xy), b // (y / gcd_xy))))


def gcd(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a
(a, b, x, y) = map(int, input().split())
ans = 0
(n, m) = (x // gcd(x, y), y // gcd(x, y))
max_v = min(a // n, b // m)
print(max_v)


def gcd(x, y):
	if x % y == 0:
		return y
	elif y % x == 0:
		return x
	elif x > y:
		return gcd(x % y, y)
	elif y > x:
		return gcd(y % x, x)
inp = list(map(int, input().split()))
a = inp[0]
b = inp[1]
x = inp[2]
y = inp[3]
k = gcd(x, y)
x = x // k
y = y // k
p = a // x
q = b // y
print(min(p, q))


from math import *
read = lambda : map(int, input().split())
(a, b, x, y) = read()
g = gcd(x, y)
xx = x // g
yy = y // g
A = [a // xx, b // yy]
print(min(A))


def gcd(a, b):
	if b == 0:
		return a
	if b == 1:
		return 1
	return gcd(b, a % b)
(a, b, w, h) = map(int, input().split())
g = gcd(w, h)
(w, h) = (w // g, h // g)
print(min(a // w, b // h))


import sys

def nod(i, j):
	while 1:
		if i * j == 0:
			return max(i, j)
		elif i >= j:
			i = i % j
		else:
			j = j % i
(a, b, x, y) = map(int, input().split())
n1 = nod(x, y)
x = x // n1
y = y // n1
print(min(a // x, b // y))


import math
(a, b, c, d) = [int(i) for i in input().split(' ')]
g = math.gcd(c, d)
c //= g
d //= g
x = a // c
y = b // d
print(min(x, y))


def gcd(aa, bb):
	if bb == 0:
		return aa
	else:
		return gcd(bb, aa % bb)
(a, b, x, y) = [int(e) for e in input().split()]
d = gcd(x, y)
x /= d
y /= d
print('%d' % min(a // x, b // y))


from math import gcd
(a, b, c, d) = map(int, input().split())
aa = gcd(c, d)
ans = min(a // (c // aa), b // (d // aa))
print(ans)


data = input()
data = data.split()
data = list(map(int, data))
a = data[0]
b = data[1]
x = data[2]
y = data[3]

def gcd(a, b):
	if a < b:
		(a, b) = (b, a)
	y = a % b
	if y == 0:
		return b
	else:
		(a, b) = (b, y)
		return gcd(a, b)
t = gcd(x, y)
x = x / t
y = y / t
time = int(min([a // x, b // y]))
print(time)


import math
(a, b, x, y) = [int(s) for s in input().split(' ')]
g = math.gcd(x, y)
x /= g
y /= g
print(min(math.floor(a / x), math.floor(b / y)))


def main():
	(a, b, x, y) = [int(z) for z in input().split()]
	print(solve(a, b, x, y))

def solve(a, b, x, y):
	div = mdc(x, y)
	x //= div
	y //= div
	return min(a // x, b // y)

def mdc(n, d):
	if n == 0:
		return d
	if d == 0:
		return n
	while n % d > 0:
		(n, d) = (d, n % d)
	return d
main()


import math
(a, b, x, y) = map(int, input().split())
hcf = math.gcd(x, y)
x = x / hcf
y = y / hcf
minib = a * y // x
minib = min(minib, b)
ans = minib // y
print(int(ans))


import math
n = [int(n) for n in input().split()]
a = n[0]
b = n[1]
x = n[2]
y = n[3]
g = math.gcd(x, y)
x = x / g
y = y / g
print(min(math.floor(a / x), math.floor(b / y)))


import math

def kek(n, m):
	k = math.gcd(n, m)
	return (n // k, m // k)
(a, b, x, y) = map(int, input().split())
(x, y) = kek(x, y)
print(math.floor(min(a / x, b / y)))


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
(a, b, x, y) = map(int, input().split())
gc = gcd(x, y)
x = int(x / gc)
y = int(y / gc)
m = a // x
n = b // y
if m < n:
	print(m)
else:
	print(n)


import math as m
(a, b, c, d) = map(int, input().split())
z = m.gcd(c, d)
(c, d) = (c // z, d // z)
print(min(a // c, b // d))


(a, b, c, d) = map(int, input().split())

def HCF(c, d):
	while True:
		if d == 0:
			break
		elif c >= d:
			k = c % d
			c = d
			d = k
		else:
			(c, d) = (d, c)
	return c
k = HCF(c, d)
c = c // k
d = d // k
print(min(a // c, b // d))


import math as m
(a, b, x, y) = [int(i) for i in input().split()]
gc = m.gcd(x, y)
x //= gc
y //= gc
print(min(a // x, b // y))


import math
try:
	(a, b, x, y) = map(int, input().split())
	g = math.gcd(x, y)
	x = x / g
	y = y / g
	print(int(min(a / x, b / y)))
except EOFError:
	pass


from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque
from collections import Counter

def read():
	return int(input())

def readmap():
	return map(int, input().split())

def readlist():
	return list(map(int, input().split()))
(a, b, x, y) = readmap()
g = math.gcd(x, y)
print(min(a // (x // g), b // (y // g)))


(a, b, x, y) = [int(i) for i in input().split(' ')]

def nod(a, b):
	while a != 0 and b != 0:
		if a > b:
			a = a % b
		else:
			b = b % a
	return a + b
c = nod(x, y)
x = x / c
y = y / c
print(min(int(a / x), int(b / y)))


import math
(a, b, x, y) = map(int, input().split())
res = 0
g = math.gcd(x, y)
x = x // g
y = y // g
print(min(a // x, b // y))


import sys
import math

def gcd(x, y):
	while y != 0:
		(x, y) = (y, x % y)
	return x
(a, b, x, y) = map(int, input().split())
maka = gcd(x, y)
(x, y) = (x // maka, y // maka)
print(min(a // x, b // y))


def main():
	(p, q, x, y) = map(int, input().split())
	(a, b) = (x, y)
	while a != 0 and b != 0:
		if a > b:
			a %= b
		else:
			b %= a
	g = a + b
	x //= g
	y //= g
	print(min(p // x, q // y))
main()


a = [int(k) for k in input().split()]

def f(x, y):
	r = y % x
	if r == 0:
		return x
	else:
		return f(r, x)
b = min(a[2], a[3])
c = max(a[2], a[3])
d = a[2] / f(b, c)
e = a[3] / f(b, c)
f = int(a[0] / d)
g = int(a[1] / e)
print(min(f, g))


import math

def dtb(n):
	return bin(n).replace('0b', '')

def btd(n):
	return int(n, 2)
t = 1
for k in range(t):
	(a, b, x, y) = map(int, input().split())
	z = math.gcd(x, y)
	x = x // z
	y = y // z
	ans = min(a // x, b // y)
	print(ans)


def getMin(a, b):
	if a == b:
		return int(b)
	if a < b:
		return int(a)
	else:
		return int(b)

def getGCD(a, b):
	while a != 0 and b != 0:
		if a > b:
			a %= b
		else:
			b %= a
	gcd = a + b
	return gcd
nums = [int(x) for x in input().split()]
a = nums[0]
b = nums[1]
x = nums[2]
y = nums[3]
gcd = getGCD(x, y)
a_x = a // (x / gcd)
b_y = b // (y / gcd)
print(getMin(a_x, b_y))


(a, b, x, y) = map(int, input().split())
import math
g = math.gcd(x, y)
if g == 1:
	if x > a or y > b:
		print(0)
		exit(0)
	p = a // x
	q = b // y
	m = min(p, q)
	print(m)
else:
	x = x // g
	y = y // g
	if x > a or y > b:
		print(0)
		exit(0)
	p = a // x
	q = b // y
	m = min(p, q)
	print(m)


def gcd(n, m):
	if n == 0:
		return m
	return gcd(m % n, n)
(a, b, x, y) = map(int, input().split())
c = gcd(x, y)
while c > 1:
	x = x // c
	y = y // c
	c = gcd(x, y)
ans1 = a // x
ans2 = b // y
print(min(ans1, ans2))


import math
(a, b, x, y) = map(int, input().split())
z = math.gcd(x, y)
flag = 0
x = x // z
y = y // z
if x > a or y > b:
	print(0)
	flag = 1
if flag == 0:
	print(min(a // x, b // y))


import math
(a, b, x, y) = [int(x) for x in input().split(' ')]
common = math.gcd(x, y)
(x, y) = (x // common, y // common)
Min = min(a // x, b // y)
print(Min)


import math
(a, b, x, y) = map(int, input().split())
c = math.gcd(x, y)
d = x / c
e = y / c
f = a / d
g = b / e
print(int(min(f, g)))


from fractions import Fraction

def main():
	(a, b, x, y) = list(map(int, input().split()))
	ratio = Fraction(x, y)
	x = ratio.numerator
	y = ratio.denominator
	print(min(a // x, b // y))
main()


import math
(a, b, x, y) = list(map(int, input().strip().split()))
ans = 0
g = math.gcd(x, y)
x = x / g
y = y / g
ans = min(math.floor(a / x), math.floor(b / y))
print(ans)


def gcd(q, w):
	while w:
		(q, w) = (w, q % w)
	return q
(a, b, x, y) = map(int, input().split())
g = x * y // gcd(x, y)
h = g // x
(l, r) = (0, b * x // g + 1)
while r - l > 1:
	m = (r + l) // 2
	if m * g // y <= a:
		l = m
	else:
		r = m
print(l)


import math
(a, b, x, y) = map(int, input().split())
xy = math.gcd(x, y)
newx = x // xy
newy = y // xy
print(min(a // newx, b // newy))


(a, b, x, y) = map(int, input().split())
h = x
h1 = y
while x != 0 and y != 0:
	if x > y:
		x %= y
	else:
		y %= x
gcd = x + y
if gcd > 1:
	h /= gcd
	h1 /= gcd
print(int(min(a // int(h), b // int(h1))))


import math
(a, b, x, y) = map(int, input().split())
lcm = int(x * y / math.gcd(x, y))
v1 = a * y - a * y % lcm
v2 = lcm
ans = max(0, int(1 + (v1 - v2) / lcm))
v1 = b * x - b * x % lcm
ans = min(ans, int(1 + (v1 - v2) / lcm))
ans = max(0, ans)
print(ans)


def hcfnaive(a, b):
	if b == 0:
		return a
	else:
		return hcfnaive(b, a % b)
(a, b, x, y) = input().split()
a = int(a)
b = int(b)
x = int(x)
y = int(y)
s = hcfnaive(x, y)
x = x / s
y = y / s
total1 = a / x
total1 = int(total1)
total2 = b / y
total2 = int(total2)
print(min(total1, total2))


import math

def main():
	(a, b, x, y) = map(int, input().rstrip().split())
	gcd = math.gcd(x, y)
	x = x / gcd
	y = y / gcd
	print(min(int(a / x), int(b / y)))
main()


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
(a, b, x, y) = ei()
g = gcd(x, y)
x = x / g
y = y / g
print(int(min(a // x, b // y)))


def gcd(a, b):
	if a < b:
		(a, b) = (b, a)
	while b:
		(a, b) = (b, a % b)
	return a
(a, b, x, y) = map(int, input().split())
nod = gcd(x, y)
x //= nod
y //= nod
b = min(b, a * y // x)
print(b // y)


def gcd(a, b):
	if a == 0:
		return b
	elif a > b:
		return gcd(b, a)
	else:
		return gcd(b % a, a)
(a, b, x, y) = map(int, input().split())
k = gcd(x, y)
x = x // k
y = y // k
x1 = a // x
y1 = b // y
print(min(x1, y1))


import sys, math
(a, b, x, y) = map(int, sys.stdin.readline().split())
temp = math.gcd(x, y)
x //= temp
y //= temp
width = min(a, int(b * (x / y)))
print(width // x)


from fractions import Fraction
(a, b, x, y) = map(int, input().split())
sx = Fraction(x, y).numerator
sy = Fraction(x, y).denominator
print(int(min(a // sx, b // sy)))


import math
G = math.gcd
F = math.floor
import decimal
D = decimal.Decimal
l1 = [int(x) for x in input().split()]
(a, b, x, y) = (l1[0], l1[1], l1[2], l1[3])
f = G(x, y)
x = D(x / f)
y = D(y / f)
width = a
length = b
if length < y or width < x:
	print(0)
else:
	first = str(D(length / y))
	if '.' in first:
		first = ''.join(list(first)[:first.index('.')])
	second = str(D(int(width / x)))
	if '.' in second:
		second = ''.join(list(second)[:second.index('.')])
	first1 = first.rjust(10 ** 5, '0')
	second1 = second.rjust(10 ** 5, '0')
	if first1 > second1:
		print(second)
	else:
		print(first)


from sys import stdin
from fractions import Fraction
input = lambda : stdin.readline()

def main():
	(A, B, X, Y) = map(int, input().split())
	xy = Fraction(X, Y)
	x = xy.numerator
	y = xy.denominator
	ans = min(A // x, B // y)
	print(ans)
main()


def nod(a, b):
	while a > 0 and b > 0:
		if a > b:
			a %= b
		else:
			b %= a
	return a + b
(a, b, x, y) = map(int, input().split())
n = nod(x, y)
x //= n
y //= n
mn = min(a // x, b // y)
print(mn)


def NOD(x, y):
	if y == 0:
		return x
	return NOD(y, x % y)
(a, b, x, y) = map(int, input().split())
(h_0, w_0) = (y // NOD(max(x, y), min(x, y)), x // NOD(max(x, y), min(x, y)))
print(min(a // w_0, b // h_0))


def nod(a, b):
	if b == 0:
		return a
	else:
		return nod(b, a % b)
(a, b, x, y) = map(int, input().split())
n = nod(x, y)
x1 = x // n
y1 = y // n
print(min(a // x1, b // y1))


def gcd(x, y):
	while y != 0:
		t = y
		y = x % y
		x = t
	return x
(a, b, x, y) = [int(x) for x in input().split()]
thegcd = gcd(x, y)
x = x // thegcd
y = y // thegcd
print(min(a // x, b // y))


def main():
	from math import gcd
	(a, b, x, y) = list(map(int, input().split()))
	c = gcd(x, y)
	print(int(min(a / (x / c), b / (y / c))))
main()


import math
(a, b, x, y) = map(int, input().split())
gc = math.gcd(x, y)
x = x // gc
y = y // gc
ina = x
inb = y
ct = 1
print(min(a // ina, b // inb))


import math
a1 = list(map(int, input().split()))
a = a1[0]
b = a1[1]
x = a1[2]
y = a1[-1]
s = math.gcd(x, y)
x1 = x
y1 = y
if s != 1:
	x1 = x1 // s
	y1 = y1 // s
i = 1
count = 0
t = min(a // x1, b // y1)
print(t)


def gcd(w, h):
	if w > h:
		if w % h == 0:
			return h
		else:
			return gcd(w % h, h)
	elif h % w == 0:
		return w
	else:
		return gcd(w, h % w)
(a, b, w, h) = map(int, input().split())
k = gcd(w, h)
w //= k
h //= k
print(min(a // w, b // h))


def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
(A, B, X, Y) = map(int, input().split())
g = GCD(X, Y)
X //= g
Y //= g
c = A // X
h = min(B, Y * c)
print(h // Y)


from math import gcd
(a, b, x, y) = map(int, input().split(' '))
g = gcd(x, y)
n1 = a * g // x
n2 = b * g // y
print(min(n1, n2))


import math
(a, b, x, y) = list(map(int, input().split()))

def gcd(m, n):
	if n == 0:
		return m
	if n == 1:
		return n
	remainder = m % n
	return gcd(n, remainder)
gcd_v = gcd(x, y)
x = x // gcd_v
y = y // gcd_v
m = a // x
n = b // y
res = min(m, n)
print(res)


import math
a = list(map(int, input().split()))
c = math.gcd(a[2], a[3])
x = a[0] * c / a[2]
y = a[1] * c / a[3]
z = min(x, y)
print(int(z))