#include <bits/stdc++.h>
using namespace std;
int v[1003];
int main() {
  long long a, b, x, y, c, d, r, cx, cy;
  cin >> a >> b >> x >> y;
  cx = x;
  cy = y;
  while (y > 0) {
    r = x % y;
    x = y;
    y = r;
  }
  c = cx / x;
  d = cy / x;
  cout << min(a / c, b / d);
  return 0;
}
