#include <bits/stdc++.h>
using namespace std;
struct cmp {
  bool operator()(long long a, long long b) { return (a > b); }
};
long long ceil(const long long &a, const long long &b) {
  if (a % b == 0) return a / b;
  return a / b + 1;
}
long long mod = 1000000007;
const long long N = 100005;
long long phi(long long n) {
  long long result = n;
  for (long long p = 2; p * p <= n; p++) {
    if (n % p == 0) {
      while (n % p == 0) {
        n /= p;
      }
      result -= result / p;
    }
  }
  if (n > 1) {
    result -= result / n;
  }
  return result;
}
long long c1, c2, x, y;
bool solve(long long x) {
  long long z1 = phi(x);
  long long z2 = phi(y);
  if (z1 >= c1 && z2 >= c2) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> c1 >> c2 >> x >> y;
  long long l = 0, r = 1e9;
  while (l + 1 < r) {
    long long mid = (l + r) >> 1;
    if (solve(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cout << r;
  return 0;
}
