#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
inline long long read() {
  long long x = 0, f = 1;
  char ch;
  for (ch = getchar(); !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + ch - '0';
  return x * f;
}
long long gcd(long long x, long long y) {
  if (!y) return x;
  return gcd(y, x % y);
}
int main() {
  a = read(), b = read(), x = read(), y = read();
  long long g = gcd(x, y);
  x /= g, y = y /= g;
  printf("%I64d\n", min(a / x, b / y));
  return 0;
}
