#include <bits/stdc++.h>
using namespace std;
long long n, m, cnt1, cnt2, k1, k2, k3, kq;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
bool check(long long ans, long long cnt1, long long cnt2) {
  long long bcnn;
  bcnn = n * m / gcd(n, m);
  k3 = ans / bcnn;
  ans -= k3;
  k1 = ans / n;
  k2 = ans / m;
  k1 -= k3;
  k2 -= k3;
  ans -= k1;
  ans -= k2;
  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;
}
