#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, x, n, y, c1, c2, cnt, ad = 0, m, mcnt, ans;
  scanf("%d %d %d %d", &c1, &c2, &x, &y);
  cnt = c1;
  n = x;
  m = y;
  mcnt = c2;
  i = 1;
  while (i * n <= cnt) {
    if (mcnt && i % m != 0) {
      mcnt--;
    }
    ad++;
    i++;
    cnt++;
  }
  if (mcnt) {
    while (mcnt) {
      if (cnt % m != 0) {
        mcnt--;
      }
      cnt++;
    }
  }
  ans = cnt;
  cnt = c2;
  n = y;
  m = x;
  mcnt = c1;
  i = 1;
  while (i * n <= cnt) {
    if (mcnt && i % m != 0) {
      mcnt--;
    }
    ad++;
    i++;
    cnt++;
  }
  if (mcnt) {
    while (mcnt) {
      if (cnt % m != 0) {
        mcnt--;
      }
      cnt++;
    }
  }
  ans = min(cnt, ans);
  printf("%d", ans);
}
