#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, x, y, xtemp, ytemp, temp, n, i, j;
int main() {
  cin >> a >> b >> x >> y;
  xtemp = x;
  ytemp = y;
  if (xtemp < ytemp) {
    temp = xtemp;
    xtemp = ytemp;
    ytemp = temp;
  }
  while ((xtemp % ytemp) != 0) {
    temp = ytemp;
    ytemp = (long long)(xtemp % ytemp);
    xtemp = temp;
  }
  x = (long long)(x / ytemp);
  y = (long long)(y / ytemp);
  i = (long long)(a / x);
  j = (long long)(b / y);
  if (i > j)
    cout << j;
  else
    cout << i;
  return 0;
}
