#include <bits/stdc++.h>
using namespace std;
int cnt1, cnt2, x, y;
bool check(int a) {
  int sum1, sum2, sum3;
  sum1 = 0, sum2 = 0, sum3 = 0;
  for (int i = 1; i <= a; i++) {
    if (i % x == 0 && i % y == 0)
      continue;
    else if (i % x != 0 && i % y == 0) {
      sum1++;
      if (sum1 > cnt1) sum1--;
    } else if (i % x == 0 && i % y != 0) {
      sum2++;
      if (sum2 > cnt2) sum2--;
    } else
      sum3++;
    if (cnt1 + cnt2 <= sum1 + sum2 + sum3) {
      return true;
      break;
    }
  }
  return false;
}
int main() {
  long long sum, left, right, mid;
  while (cin >> cnt1 >> cnt2 >> x >> y) {
    sum = cnt1 * x + cnt2 * y;
    left = 0;
    right = sum;
    while (left + 1 < right) {
      mid = (left + right) / 2;
      if (check(mid))
        right = mid;
      else
        left = mid;
    }
    cout << mid << endl;
  }
  return 0;
}
