#include <bits/stdc++.h>
using namespace std;
long long x, y, a, b;
long long gcd(long long m, long long n) {
  if (n == 0) return m;
  return gcd(n, m % n);
}
int main(void) {
  cin >> a >> b >> x >> y;
  long long gxy = gcd(x, y);
  x /= gxy;
  y /= gxy;
  long long rt = min(a / x, b / y);
  if (rt < 0) rt = 0;
  cout << rt << endl;
}
