#include <bits/stdc++.h>
using namespace std;
set<int> b, a;
int main() {
  int cn1, cn2, x, y;
  cin >> cn1 >> cn2 >> x >> y;
  int i = 0, j = 0;
  if (cn1 > cn2)
    while (b.size() != cn1) {
      if ((i + 1) % x != 0) b.insert(i + 1);
      i++;
    }
  else
    while (b.size() != cn2) {
      if ((i + 1) % y != 0) b.insert(i + 1);
      i++;
    }
  if (cn1 > cn2)
    while (a.size() != cn2) {
      if ((j + 1) % y != 0 && b.find(j + 1) == b.end()) a.insert(j + 1);
      j++;
    }
  else
    while (a.size() != cn1) {
      if ((j + 1) % x != 0 && b.find(j + 1) == b.end()) a.insert(j + 1);
      j++;
    }
  cout << max(i, j) << endl;
  return 0;
}
