#include <bits/stdc++.h>
using namespace ::std;
long long int gcd(long long int a, long long int b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
int main() {
  long long int a, b, x, y;
  cin >> a >> b >> x >> y;
  long long int div = gcd(x, y);
  x /= div;
  y /= div;
  cout << min(a / x, b / y);
}
