#include <bits/stdc++.h>
using namespace std;
long long n, m, cnt1, cnt2, k1, k2, k3, kq;
bool check(long long ans, long long cnt1, long long cnt2) {
  k3 = ans / (n * m);
  k1 = ans / n;
  k2 = ans / m;
  k1 -= k3;
  k2 -= k3;
  ans -= k1;
  ans -= k2;
  ans -= k3;
  cnt2 -= k1;
  cnt1 -= k2;
  if (cnt1 < 0) cnt1 = 0;
  if (cnt2 < 0) cnt2 = 0;
  if (ans >= cnt1 + cnt2) return true;
  return false;
}
int main() {
  cin >> cnt1 >> cnt2 >> n >> m;
  long long r, l, g;
  l = 0;
  r = 1000000000000001;
  while (l <= r) {
    g = (l + r) / 2;
    if (check(g, cnt1, cnt2)) {
      kq = g;
      r = g - 1;
    } else
      l = g + 1;
  }
  cout << kq;
}
