#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  long long a, b, x, y;
  cin >> a >> b >> x >> y;
  long long kk = gcd(x, y);
  x = x / kk;
  y = y / kk;
  long long ans = min(a / x, b / y);
  cout << ans << endl;
  return 0;
}
