#include <bits/stdc++.h>
using namespace std;
long long int a, b, x, y;
void BinSearch(long long int low, long long int high) {
  long long int mid, result;
  while (low <= high) {
    mid = (low + high) >> 1;
    long long int p = (mid - (mid / x));
    long long int q = (mid - (mid / y));
    long long int r = (mid - (mid / (x * y)));
    if (a <= p && b <= q && a + b <= r) {
      result = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  cout << result << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b >> x >> y;
  BinSearch(1, 2e9);
  return 0;
}
