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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
  return os << "(" << p.first << "," << p.second << ")";
}
template <typename T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
  bool first = true;
  os << "{";
  for (unsigned int i = 0; i < v.size(); i++) {
    if (!first) os << ",";
    os << v[i];
    first = false;
  }
  return os << "}";
}
template <typename T>
inline ostream& operator<<(ostream& os, const set<T>& v) {
  bool first = true;
  os << "{";
  for (typename set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
    if (!first) os << ",";
    os << *ii;
    first = false;
  }
  return os << "}";
}
template <typename T>
inline ostream& operator<<(ostream& os, const multiset<T>& v) {
  bool first = true;
  os << "{";
  for (typename multiset<T>::const_iterator ii = v.begin(); ii != v.end();
       ++ii) {
    if (!first) os << ",";
    os << *ii;
    first = false;
  }
  return os << "}";
}
template <typename T1, typename T2>
inline ostream& operator<<(ostream& os, const map<T1, T2>& v) {
  bool first = true;
  os << "{";
  for (typename map<T1, T2>::const_iterator ii = v.begin(); ii != v.end();
       ++ii) {
    if (!first) os << ",";
    os << *ii;
    first = false;
  }
  return os << "}";
}
template <typename T>
bool isPrime(T n) {
  T i, lmt = sqrt(n);
  for (i = 2; i <= lmt; i++)
    if (n % i == 0) return false;
  return true;
}
template <typename T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename T>
T BigMod(T b, T p, T m) {
  if (p == 0)
    return 1 % m;
  else if (p & 1)
    return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;
  else {
    T s = BigMod(b, p / 2, m);
    return ((s % m) * (s % m)) % m;
  }
}
template <typename T>
T power(T b, T p) {
  if (p == 0)
    return 1;
  else if (p & 1)
    return b * power(b, p - 1);
  else {
    T ret = power(b, p / 2);
    return ret * ret;
  }
}
template <typename T>
T ModInv(T b, T m) {
  if (isPrime(b))
    return BigMod(b, m - 2, m) % m;
  else if (gcd(b, m) == 1)
    return BigMod(b, m - 1, m) % m;
}
template <typename T>
T egcd(T a, T b, T& x, T& y) {
  T d;
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  } else {
    T x1, y1;
    d = egcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
  }
  return d;
}
int toint(string s) {
  int i, j, l;
  int num;
  l = s.size();
  for (i = l - 1, j = 0, num = 0; i >= 0; i--, j++) {
    num += (s[i] - 48) * power(10, j);
  }
  return num;
}
const double pi = acos(-1);
const int inf = (1 << 30);
const long long INF = (1LL << 62) - 1;
const int mod = (int)1e9 + 7;
const long long MOD = (long long)1e9 + 7;
const double EPS = 1e-9;
const int dx8[] = {-1, 0, +1, -1, +1, -1, 0, +1};
const int dy8[] = {+1, +1, +1, 0, 0, -1, -1, -1};
const int dx4[] = {0, -1, +1, 0};
const int dy4[] = {+1, 0, 0, -1};
const int dx2[] = {+1, 0};
const int dy2[] = {0, +1};
const int dxkn[] = {1, -1, 1, -1, 2, -2, -2, 2};
const int dykn[] = {2, 2, -2, -2, 1, 1, -1, -1};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long a, b, x, y, l1, l2, ans, g;
  cin >> a >> b >> x >> y;
  g = gcd(x, y);
  x = x / g;
  y = y / g;
  l1 = a / x;
  l2 = b / y;
  ans = min(l1, l2);
  cout << ans << "\n";
  return 0;
}