#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
long long gcdxy, Max1, Max2;
long long gcd(long long x, long long y) { return y > 0 ? gcd(y, x % y) : x; }
int main() {
  scanf("%lld%lld%lld%lld", &a, &b, &x, &y);
  if (x < y) swap(x, y), swap(a, b);
  long long z = gcd(x, y);
  x /= z;
  y /= z;
  Max1 = a / x;
  Max2 = b / y;
  printf("%lld\n", min(Max1, Max2));
  return 0;
}
