#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<long long> v;
  long long k = 0, i, a, b, x, y, s, t, mx = 0;
  cin >> a >> b >> x >> y;
  s = a;
  t = b;
  while (1) {
    k++;
    if (t <= 0 && s <= 0) break;
    if (a > b) {
      if (k % x != 0 && s > 0) {
        if (mx <= k) mx = k;
        s--;
        continue;
      }
      if (k % y != 0 && t > 0) {
        if (mx <= k) mx = k;
        t--;
      }
    } else {
      if (k % y != 0 && t > 0) {
        if (mx <= k) mx = k;
        t--;
        continue;
      }
      if (k % x != 0 && s > 0) {
        if (mx <= k) mx = k;
        s--;
      }
    }
  }
  cout << mx << endl;
  return 0;
}
