#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
long long gcd(long long m, long long n) {
  long long r;
  while (n != 0) {
    r = m % n;
    m = n;
    n = r;
  }
  return m;
}
int main() {
  cin >> a >> b >> x >> y;
  long long keep = gcd(x, y);
  x /= keep;
  y /= keep;
  cout << min(a / x, b / y);
}
