#include <bits/stdc++.h>
using namespace std;
ifstream in;
ofstream out;
const long long kk = 1000;
const long long MOD = 10e9 + 7;
long long a, b, x, y;
long long GCD(long long n, unsigned long long m) {
  while (n != 0 && m != 0) {
    if (n > m) {
      n %= m;
    } else {
      m %= n;
    }
  }
  return (n + m);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> a >> b >> x >> y;
  long long x1, y1;
  long long k = GCD(x, y);
  x /= k;
  y /= k;
  cout << min(a / x, b / y);
  return 0;
}
