#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n1, k1, n2, k2, x, y, v, n;
  cin >> n1 >> n2 >> x >> y;
  k1 = k2 = 0;
  n = 1000000000;
  if (x > y) {
    for (int i = 1; i <= n; i++) {
      if ((i % x) != 0) {
        v = i;
        k1++;
      }
      if (k1 == n1) {
        break;
      }
    }
    for (int i = x; i <= v; i = i + x)
      if ((i % y) != 0 & (i % x) == 0) k2++;
    if (k2 >= n2) {
      cout << v << endl;
      return 0;
    }
    for (int i = v + 1; i <= n; i++) {
      if ((i % y) != 0) {
        k2++;
        v = i;
      }
      if (k2 == n2) {
        cout << v << endl;
        return 0;
      }
    }
  }
  if (y > x) {
    for (int i = 1; i <= n; i++) {
      if ((i % y) != 0) {
        v = i;
        k2++;
      }
      if (k2 == n2) break;
    }
    for (int i = y; i <= v; i = i + y)
      if ((i % x) != 0 & (i % y) == 0) k1++;
    if (k1 >= n1) {
      cout << v << endl;
      return 0;
    }
    for (int i = v + 1; i <= n; i++) {
      if ((i % x) != 0) {
        k1++;
        v = i;
      }
      if (k1 == n1) {
        cout << v << endl;
        return 0;
      }
    }
  }
  return 0;
}
