#include <bits/stdc++.h>
using namespace std;
int cnt1, cnt2, x, y;
map<int, bool> m;
void Solve(int d, int acnt) {
  int i = 2;
  int maxim = 0, cnt = 1;
  m[1] = true;
  while (cnt != acnt) {
    if (i % d != 0) {
      m[i] = true;
      ++cnt;
    }
    ++i;
  }
  maxim = max(maxim, i - 1);
  if (d == x) {
    d = y;
    acnt = cnt2;
  } else {
    d = x;
    acnt = cnt1;
  }
  i = 2;
  cnt = 0;
  while (cnt != acnt) {
    if ((i % d != 0) && (!m[i])) {
      ++cnt;
    }
    ++i;
  }
  maxim = max(maxim, i - 1);
  cout << maxim << '\n';
}
int main() {
  cin.sync_with_stdio(false);
  cin >> cnt1 >> cnt2 >> x >> y;
  if (cnt1 >= cnt2)
    Solve(x, cnt1);
  else
    Solve(y, cnt2);
  return 0;
}
