#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
vector<long long> vec;
long long ans, sum1, sum2, sum;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  long long n, m, x, y, g, x1, y1;
  scanf("%lld%lld%lld%lld", &n, &m, &x, &y);
  g = gcd(x, y);
  x /= g, y /= g;
  sum1 = n / x;
  sum2 = m / y;
  ans = min(sum1, sum2);
  printf("%lld\n", ans);
  return 0;
}
