#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
long long gcd(long long c, long long d) {
  if (d == 0)
    return c;
  else
    return gcd(d, c % d);
}
int main() {
  scanf("%lld %lld %lld %lld", &a, &b, &x, &y);
  long long k = gcd(x, y);
  x /= k;
  y /= k;
  long long ans = min(a / x, b / y);
  printf("%lld", ans);
  return 0;
}
