#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y, c, d;
long long gcd(long long x, long long y) {
  if (!y) {
    return x;
  } else {
    return gcd(y, x % y);
  }
}
int main() {
  cin >> a >> b >> x >> y;
  long long g = gcd(x, y);
  x /= g;
  y /= g;
  c = a / x;
  d = b / y;
  cout << min(c, d) << endl;
  return 0;
}
