#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000000;
const int MOD = 1000000007;
const long long INF = 1E11;
long long l, r, mid, cnt, cnt1, cnt2, x, y;
bool check(long long cnt, long long cnt1, long long cnt2) {
  long long xy = cnt / x / y;
  long long X = cnt / x - xy;
  long long Y = cnt / y - xy;
  cnt1 -= Y;
  cnt2 -= X;
  if (cnt1 < 0) cnt1 = 0;
  if (cnt2 < 0) cnt2 = 0;
  if (cnt1 + cnt2 <= cnt - xy - X - Y) return true;
  return false;
}
int main() {
  cin >> cnt1 >> cnt2 >> x >> y;
  l = 0;
  r = INF;
  while (l < r - 1) {
    mid = (l + r) / 2;
    if (check(mid, cnt1, cnt2)) {
      r = mid;
    } else
      l = mid;
  }
  cout << r << endl;
  return 0;
}
