#include <bits/stdc++.h>
using namespace std;
int main() {
  int cnt1, cnt2, x, y;
  while (cin >> cnt1 >> cnt2 >> x >> y) {
    int tmp1, tmp2;
    tmp1 = cnt1;
    tmp2 = cnt2;
    int i = 0;
    for (i = 1; tmp1 != 0 || tmp2 != 0; i++) {
      if (i % x != 0 && tmp1 > 0) {
        tmp1--;
      } else if (i % y != 0 && tmp2 > 0) {
        tmp2--;
      }
    }
    tmp1 = cnt1;
    tmp2 = cnt2;
    int j = 0;
    for (j = 1; tmp1 != 0 || tmp2 != 0; j++) {
      if (j % y != 0 && tmp2 > 0) {
        tmp2--;
      } else if (j % x != 0 && tmp1 > 0) {
        tmp1--;
      }
    }
    cout << min(j - 1, i - 1) << endl;
  }
}
