#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int a, b, x, y;
  cin >> a >> b >> x >> y;
  long long int cd = gcd(x, y);
  x /= cd;
  y /= cd;
  long long int count = min(a / x, b / y);
  cout << count << endl;
  return 0;
}
