#include <bits/stdc++.h>
using namespace std;
int cnt1, cnt2, x, y;
long long lcm;
long long binarySearch(long long b, long long e) {
  if (e == b) return b;
  if (e == b + 1) {
    if (b - b / x >= cnt1 && b - b / y >= cnt2) return b;
    return e;
  }
  long long m = (b + e) / 2;
  if (m - m / x >= cnt1 && m - m / y >= cnt2) return binarySearch(b, m);
  return binarySearch(m, e);
}
int main() {
  scanf("%d%d%d%d", &cnt1, &cnt2, &x, &y);
  long long ans = binarySearch(2, 1000000000000000000);
  cout << ans << endl;
  return 0;
}
