#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long int LINF = 0x3f3f3f3f3f3f3f3fll;
const long double pi = acos(-1);
const int MOD = 1e9 + 7;
long long int n, m, x, y;
long long int bb(long long int b, long long int e) {
  if (b == e) return b;
  long long int mid = (b + e) / 2;
  long long int resta1 = mid - mid / x;
  long long int resta2 = mid - mid / y;
  if (resta1 >= n and resta2 >= m) return bb(b, mid);
  return bb(mid + 1, e);
}
int main() {
  cin >> n >> m >> x >> y;
  long long int resp = bb(0, 1000000000000ll);
  cout << resp << endl;
  return 0;
}
