#include <bits/stdc++.h>
using namespace std;
const unsigned long long mod = 1e9 + 7;
void fast() {
  ios::sync_with_stdio(0);
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
}
long long GCD(long long a, long long b) {
  if (a == 0) return b;
  return GCD(b % a, a);
}
int main() {
  unsigned long long a, b, x, y;
  cin >> a >> b >> x >> y;
  long long g = GCD(x, y);
  x /= g;
  y /= g;
  cout << min(a / x, b / y);
  return 0;
}
