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