#include <bits/stdc++.h>
using namespace std;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
  while (b) {
    unsigned long long t = a % b;
    a = b;
    b = t;
  }
  return a;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  unsigned long long a, b, x, y;
  cin >> a >> b >> x >> y;
  unsigned long long g = gcd(x, y);
  x /= g;
  y /= g;
  cout << min(a / x, b / y) << '\n';
  return 0;
}
