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