#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
signed main() {
  cin.tie(0);
  cout << setprecision(10);
  long long a, b, x, y;
  cin >> a >> b >> x >> y;
  long long tmp = gcd(x, y);
  x = x / tmp;
  y = y / tmp;
  cout << min(a / x, b / y) << endl;
}
