#include <bits/stdc++.h>
using namespace std;
long long nsd(long long a, long long b) {
  if (a == 0) return b;
  if (b == 0) return a;
  if (b > a) {
    long long temp = b;
    b = a;
    a = temp;
  }
  return nsd(a % b, b);
}
int main() {
  long long a, b, x, y;
  cin >> a >> b >> x >> y;
  long long nsdxy = nsd(x, y);
  x = x / nsdxy;
  y = y / nsdxy;
  cout << min(a / x, b / y);
  return 0;
}
