#include <bits/stdc++.h>
using namespace std;
int n, m, x, y;
bool can(long long t) {
  if (t - t / x < n) return 0;
  if (t - t / y < m) return 0;
  int lcm = x * y;
  if (t - t / lcm < n + m) return 0;
  return 1;
}
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> x >> y;
  long long st = 1, en = 1e12, mid;
  while (st < en) {
    mid = st + en >> 1;
    if (can(mid))
      en = mid;
    else
      st = mid + 1;
  }
  cout << en << '\n';
  return 0;
}
