#include <bits/stdc++.h>
#pragma gcc optimize(o3)
using namespace std;
long long qpow(long long x, long long y) {
  return y ? (y & 1 ? x * qpow(x, y - 1) % 1000000007
                    : qpow(x * x % 1000000007, y / 2))
           : 1;
}
template <typename T>
inline void read(T& x) {
  x = 0;
  char c;
  int sign = 1;
  do {
    c = getchar();
    if (c == '-') sign = -1;
  } while (!isdigit(c));
  do {
    x = x * 10 + c - '0';
    c = getchar();
  } while (isdigit(c));
  x *= sign;
}
long long a, b, x, y, k;
long long gcd(long long p, long long q) {
  if (q == 0) return p;
  return gcd(q, p % q);
}
int main() {
  read(a), read(b), read(x), read(y);
  k = gcd(x, y);
  x /= k, y /= k;
  printf("%I64d\n", min(a / x, b / y));
  return 0;
}
