#include <bits/stdc++.h>
using namespace std;
int main() {
  int c1, c2, x, y, i, t1, t2, p, q;
  cin >> c1 >> c2 >> x >> y;
  t1 = 0;
  t2 = 0;
  for (i = 1; t1 < c1 || t2 < c2; i++) {
    if (t1 < c1 && i % x != 0) {
      t1++;
      continue;
    }
    if (t2 < c2 && i % y != 0) t2++;
  }
  p = i;
  t1 = 0;
  t2 = 0;
  for (i = 1; t1 < c1 || t2 < c2; i++) {
    if (t2 < c2 && i % y != 0) {
      t2++;
      continue;
    }
    if (t1 < c1 && i % x != 0) t1++;
  }
  if (p < i)
    cout << p - 1 << endl;
  else
    cout << i - 1 << endl;
  return 0;
}
