#include <bits/stdc++.h>
using namespace std;
long long GCD(long long m, long long n);
int main() {
  long long i, j, k, m, n, val, t = 0, cnt = 0, test;
  cin >> n >> m >> j >> k;
  val = GCD(j, k);
  j /= val;
  k /= val;
  cout << min(n / j, m / k) << endl;
  return 0;
}
long long GCD(long long m, long long n) {
  long long divisor, divident, rem = 1;
  divident = (m > n ? m : n);
  divisor = (m > n ? n : m);
  while (rem != 0) {
    rem = divident % divisor;
    divident = divisor;
    divisor = rem;
  }
  return divident;
}
