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