#include <bits/stdc++.h>
using namespace std;
long long nzd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return nzd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(10);
  long long a, b, x, y;
  cin >> a >> b >> x >> y;
  long long nzdd = nzd(x, y);
  x = x / nzdd;
  y = y / nzdd;
  long long r1, r2;
  r1 = a / x;
  r2 = b / y;
  cout << min(r1, r2);
}
