#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (a == 0 && b != 0) return b;
  if (a != 0 && b == 0) return a;
  if (a == b) return a;
  if (a > b) return gcd(a % b, b);
  return gcd(a, b % a);
}
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 g = gcd(x, y);
  x = x / g;
  y = y / g;
  if (x > a || y > b)
    cout << "0" << endl;
  else {
    cout << min((a / x), (b / y)) << endl;
  }
}
