#include <bits/stdc++.h>
using namespace std;
long long n, m;
int gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  long long a, b = 0, c = 0, t, lj = 0, k = 0, r = 0, l = 0, sum = 0, rr,
               mn = LLONG_MAX, mx = LLONG_MIN, w, y = 0, x = 0, d, neg = 0,
               pos = 0, ans = 0;
  string s5 = "", s2 = "", s3 = "", s1 = "", s = "";
  map<char, long long> mp;
  cin >> a >> b >> x >> y;
  c = gcd(x, y);
  while (c != 1) {
    x /= c;
    y /= c;
    c = gcd(x, y);
  }
  cout << min(b / y, a / x);
}
