#include <bits/stdc++.h>
using namespace std;
void in(int &x) {
  char ch;
  int minus = 0;
  while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
    ;
  if (ch == '-')
    minus = 1, x = 0;
  else
    x = ch - '0';
  while (ch = getchar(), ch >= '0' && ch <= '9') x = x * 10 + ch - '0';
  if (minus) x = -x;
}
void in(long long &x) {
  char ch;
  int minus = 0;
  while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
    ;
  if (ch == '-')
    minus = 1, x = 0;
  else
    x = ch - '0';
  while (ch = getchar(), ch >= '0' && ch <= '9') x = x * 10 + ch - '0';
  if (minus) x = -x;
}
void out(int x) {
  char hc[30];
  int len, minus = 0;
  if (x < 0) minus = 1, x = -x;
  len = 0;
  hc[len++] = x % 10 + '0';
  while (x /= 10) hc[len++] = x % 10 + '0';
  if (minus) putchar('-');
  for (int i = len - 1; i >= 0; i--) putchar(hc[i]);
}
void out(long long x) {
  char hc[30];
  int len, minus = 0;
  if (x < 0) minus = 1, x = -x;
  len = 0;
  hc[len++] = x % 10 + '0';
  while (x /= 10) hc[len++] = x % 10 + '0';
  if (minus) putchar('-');
  for (int i = len - 1; i >= 0; i--) putchar(hc[i]);
}
long long cnt1, cnt2, cnt, x, y, v, ans = 0;
long long sep(long long div, long long lim) {
  long long l = cnt, r = cnt << 1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (mid - mid / div >= lim)
      r = mid - 1;
    else
      l = mid + 1;
  }
  return r + 1;
}
int main() {
  in(cnt1);
  in(cnt2);
  in(x);
  in(y);
  cnt = cnt1 + cnt2;
  ans = max(ans, sep(x * y, cnt));
  ans = max(ans, sep(x, cnt1));
  ans = max(ans, sep(y, cnt2));
  out(ans);
  putchar('\n');
  return 0;
}
