#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 r = (mid / (x * y));
    long long int p = (mid - (mid / x)) - r;
    long long int q = (mid - (mid / y)) - r;
    if (a <= p && b <= q) {
      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, 2e11);
  return 0;
}
