#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return x == 0 ? y : gcd(y % x, x); }
int main() {
  long long a, b, x, y;
  long long ans = 0;
  cin >> a >> b >> x >> y;
  long long t = gcd(x, y);
  x /= t, y /= t;
  ans = min(a / x, b / y);
  cout << ans << endl;
  return 0;
}
