#include <bits/stdc++.h>
using namespace std;
void re(long long &x) {
  x = 0;
  int b = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') b = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  if (b == -1) x *= -1;
}
long long a, b, x, y, tot;
long long gcd(long long x, long long y) {
  if (y == 0) {
    return x;
  }
  gcd(y, x % y);
}
int main() {
  re(a), re(b), re(x), re(y);
  tot = gcd(x, y);
  x = x / tot;
  y = y / tot;
  printf("%I64d", min(a / x, b / y));
  return 0;
}
