#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b, long long int m) {
  if (b == 0) return (1);
  long long int sol = power(a, b / 2, m);
  sol = (sol * sol) % m;
  if (b % 2 == 1) sol = (sol * a) % m;
  return (sol);
}
long long int hcf(long long int a, long long int b) {
  if (a % b == 0)
    return b;
  else
    return hcf(b, a % b);
}
void solve() {
  long long int a, b, x, y, x1, y1;
  cin >> a >> b >> x >> y;
  x1 = x / hcf(x, y);
  y1 = y / hcf(x, y);
  long long int w = a / x1;
  long long int l = b / y1;
  long long int sol = min(w, l);
  cout << sol;
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
