#include <bits/stdc++.h>
unsigned long long gcd(unsigned long long a, unsigned long long b) {
  while (a != 0 && b != 0) {
    if (a > b)
      a %= b;
    else
      b %= a;
  }
  return a + b;
}
int task_A() {
  int n;
  std::cin >> n;
  std::vector<int> keyboards(n, 0);
  for (int i = 0; i < n; ++i) {
    std::cin >> keyboards[i];
  }
  std::sort(keyboards.begin(), keyboards.end());
  int missing_keyboards = 0;
  for (int i = 1; i < keyboards.size(); ++i) {
    missing_keyboards += (keyboards[i] - keyboards[i - 1] - 1);
  }
  std::cout << missing_keyboards << std::endl;
  return 0;
}
int task_B() {
  unsigned long long a, b, x, y;
  std::cin >> a >> b >> x >> y;
  unsigned long long g = gcd(x, y);
  x /= g;
  y /= g;
  unsigned long long answer = std::min(a / x, b / y);
  std::cout << answer << std::endl;
  return 0;
}
int main() {
  task_B();
  return 0;
}
