#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  char c = getchar();
  long long num = 0;
  long long f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    num = (num << 3) + (num << 1) + (c ^ 48);
    c = getchar();
  }
  return num * f;
}
inline void qwq(long long x) {
  if (x > 9) qwq(x / 10);
  putchar(x % 10 + '0');
}
inline void write(long long x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  qwq(x);
  putchar('\n');
}
inline long long gcd(long long x, long long y) {
  if (x % y == 0)
    return y;
  else
    return gcd(y, x % y);
}
int main() {
  long long a = read();
  long long b = read();
  long long x = read();
  long long y = read();
  long long temp = gcd(x, y);
  x /= temp;
  y /= temp;
  if (a < x || b < y) {
    write(0);
    return 0;
  }
  long long ans = min(a / x, b / y);
  write(ans);
  return 0;
}
