#include <bits/stdc++.h>
using namespace std;
long long int gsd(long long int n1, long long int n2) {
  int k;
  if (n1 == 1 || n2 == 1) return 1;
  if (n1 % n2 == 0) return n2;
  if (n2 % n1 == 0) return n1;
  while (n1 != n2) {
    if (n1 > n2)
      n1 -= (n1 / n2) * n2;
    else
      n2 -= (n2 / n1) * n1;
    if (n1 % n2 == 0) return n2;
    if (n2 % n1 == 0) return n1;
    if (n1 == 1 || n2 == 1) return 1;
  }
  return n1;
}
int main() {
  long long int i, j, k, m, n, a, b, x, y, t, w;
  cin >> a >> b >> x >> y;
  k = gsd(x, y);
  t = x / k;
  w = y / k;
  cout << min(a / t, b / w) << endl;
  return 0;
}
