#include <bits/stdc++.h>
using namespace std;
bool check1[30000 + 50], check2[30000 + 50];
int main() {
  int cnt1, cnt2, x, y, l = 0, m = 0, n = 0, i = 1;
  cin >> cnt1 >> cnt2 >> x >> y;
  for (i = 1; i < 30000 + 50; i++) {
    if (i % x != 0 && i % y != 0)
      l++;
    else if (i % x != 0)
      m++;
    else if (i % y != 0)
      n++;
    if ((cnt1 - m > 0 ? cnt1 - m : 0) + (cnt2 - n > 0 ? cnt2 - n : 0) == l)
      break;
  }
  cout << i << endl;
  return 0;
}
