#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long linf = 1e18;
const int N = 100000 + 1;
const double eps = 1e-5;
const int mo = 1e9 + 7;
long long a, b, x, y;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  scanf("%lld %lld %lld %lld", &a, &b, &x, &y);
  long long d = gcd(x, y);
  x /= d, y /= d;
  long long ans = a / x;
  ans = min(ans, b / y);
  printf("%lld\n", ans);
  return 0;
}
