#include <bits/stdc++.h>
using namespace std;
unsigned long long int gcd(unsigned long long int m, unsigned long long int n) {
  if (n == 0) return m;
  return (n, m % n);
}
int main() {
  unsigned long long int x, y, c1, c2, pos1, pos2, v, rem1, rem2, lcm;
  cin >> c1 >> c2 >> x >> y;
  lcm = (x * y) / gcd(x, y);
  if (c1 + c2 <= x) {
    cout << min(x, c1 + c2) << endl;
    return 0;
  } else {
    pos1 = c1 / x;
    if (pos1 == 0)
      v = c1;
    else {
      v = 1;
      while (c1) {
        if (v % x == 0) {
          if (v % lcm != 0) {
            if (c2 > 0) --c2;
          }
        } else {
          c1--;
          if (c1 == 0) break;
        }
        ++v;
      }
    }
    if (c2) {
      while (c2) {
        ++v;
        if (v % y != 0) {
          c2--;
        }
      }
    }
  }
  cout << v << endl;
}
