#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int cnt1, cnt2, x, y;
  cin >> cnt1 >> cnt2 >> x >> y;
  long long int low = 1, high = 1000000000;
  long long ans = 0;
  while (low <= high) {
    long long int mid = (low + high) / 2;
    long long int g = mid / x;
    g = mid - g;
    long long int h = mid / y;
    h = mid - h;
    if ((g >= cnt1 && (h - 0) >= cnt2) || ((g - 0) >= cnt1 && h >= cnt2)) {
      ans = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  cout << ans << endl;
}
