#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1000;
const long long MAXN = 1000;
const double PI = acos(-1.0);
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
int main() {
  long long a, b, x, y;
  cin >> a >> b >> x >> y;
  long long minn = x > y ? gcd(x, y) : gcd(y, x);
  x /= minn, y /= minn;
  cout << (min(a / x, b / y));
  return 0;
}
