#include <bits/stdc++.h>
using namespace std;
long long gcd(long long p, long long q) {
  if (q == 0) return p;
  return gcd(q, p % q);
}
int main() {
  long long a, b, p, q;
  cin >> a >> b >> p >> q;
  long long d = gcd(p, q);
  p /= d;
  q /= d;
  long long ans1 = a / p, ans2 = b / q;
  cout << min(ans1, ans2) << endl;
  return 0;
}
