#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
int main() {
  long long res, res1, res2;
  long long x1, y1, a, b;
  cin >> x1 >> y1 >> a >> b;
  long long tt = gcd(a, b);
  a = a / tt;
  b = b / tt;
  res1 = x1 / a;
  res2 = y1 / b;
  res = min(res2, res1);
  cout << res << endl;
}
