#include <bits/stdc++.h>
using namespace std;
int a[1005];
long long gcd(long long a, long long b) {
  while (b) {
    long long r = a % b;
    a = b;
    b = r;
  }
  return a;
}
int main() {
  long long a, b, x, y;
  cin >> a >> b >> x >> y;
  long long a1 = gcd(x, y);
  x /= a1;
  y /= a1;
  cout << min(a / x, b / y);
  return 0;
}
