#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int a[maxn];
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
  int i, j;
  long long a, b, x, y;
  cin >> a >> b >> x >> y;
  long long g = gcd(x, y);
  x = x / g;
  y = y / g;
  long long k1 = a / x;
  long long k2 = b / y;
  cout << min(k1, k2) << endl;
  return 0;
}
