#include <bits/stdc++.h>
using namespace std;
long long nod(long long num, long long den);
int main() {
  long long a, b, x, y, numH, numL, del;
  cin >> a >> b >> x >> y;
  del = nod(x, y);
  x = x / del;
  y = y / del;
  numL = a / x;
  numH = b / y;
  if (numL > numH)
    cout << numH;
  else
    cout << numL;
}
long long nod(long long num, long long den) {
  if (den == 0)
    return num;
  else
    return nod(den, num % den);
}
