#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  char ch;
  bool flag = false;
  for (ch = getchar(); !isdigit(ch); ch = getchar())
    if (ch == '-') flag = true;
  for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  x = flag ? -x : x;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  long long a, b, x, y;
  cin >> a >> b >> x >> y;
  long long ans = 0;
  long long c = x / gcd(x, y);
  long long d = y / gcd(x, y);
  if (a < c || b < d) {
    printf("0\n");
    return 0;
  }
  ans = min(a / c, b / d);
  cout << ans << endl;
  return 0;
}
