#include <bits/stdc++.h>
using namespace std;
long long cal(long long n, long long k) { return n - n / k; }
int main() {
  ios_base::sync_with_stdio(false);
  long long c1, c2, x, y;
  cin >> c1 >> c2 >> x >> y;
  long long l = 1, r = 9223372036854775807;
  while (l < r) {
    long long m = (l + r) >> 1;
    if (cal(m, x) < c1 || cal(m, y) < c2)
      l = m + 1;
    else
      r = m;
  }
  cout << l << endl;
  return 0;
}
