#include <bits/stdc++.h>
using namespace std;
int main() {
  int cnt1, cnt2, x, y;
  cin >> cnt1 >> cnt2 >> x >> y;
  int max = 0;
  if (cnt1 < cnt2) {
    int tmp = cnt1;
    cnt1 = cnt2;
    cnt2 = tmp;
    tmp = x;
    x = y;
    y = tmp;
  }
  while (cnt1 || cnt2) {
    max++;
    if (max % x != 0 && cnt1 != 0) {
      cnt1--;
    } else if (max % y != 0 && cnt2 != 0) {
      cnt2--;
    }
  }
  cout << max << endl;
  return 0;
}
