#include <bits/stdc++.h>
using namespace std;
int cnt[2], x, y;
bool check(int v) {
  int c[2];
  c[0] = cnt[0];
  c[1] = cnt[1];
  int DivByx = v / x, DivByy = v / y;
  int DibByxandy = v / (x * y);
  c[0] = max(c[0] - DivByy, 0);
  c[1] = max(0, c[1] - DivByx);
  int rest = v - (DivByx + DivByy) + DibByxandy;
  return (rest >= (c[0] + c[1]));
}
int main() {
  for (int i = 0; i < 2; i++) cin >> cnt[i];
  cin >> x >> y;
  int s = 0, e = 2000000000;
  while (s < e) {
    int mid = s + (e - s) / 2;
    if (check(mid)) {
      e = mid;
    } else
      s = mid + 1;
  }
  cout << s << endl;
  return 0;
}
