#include <bits/stdc++.h>
using namespace std;
long long n, m, k, c, p, mx = -1000000000000000000, mn = 1000000000000000000,
                         ans;
double db, xx, yy;
long long a[100001], b[100001], d[100001], x, y, z, l, r;
char ch;
string second, t, sr[10001];
long long used[100001];
map<long long, long long> mm;
int main() {
  cin >> n >> m >> k >> c;
  l = 0;
  r = 1000000000000000000 + 1;
  while (r - l > 1) {
    long long mid = (r + l) / 2;
    x = mid - mid / k;
    y = mid - mid / c;
    z = mid - mid / c - mid / k;
    x -= z, y -= z;
    p = mid / (k * c);
    z += p;
    if (x < n) z -= (n - x);
    if (y < m) z -= (m - y);
    if (z >= 0)
      r = mid;
    else
      l = mid;
  }
  cout << r << endl;
  return 0;
}
