#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void Int(T &n) {
  n = 0;
  int f = 1;
  register int ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}
template <typename T>
T gcd(T a, T b) {
  return !b ? a : gcd(b, a % b);
}
template <typename T>
inline void umin(T &a, T b) {
  a = a < b ? a : b;
}
template <typename T>
inline void umax(T &a, T b) {
  a = a > b ? a : b;
}
template <typename T, typename W>
inline void Int(T &x, W &y) {
  Int(x), Int(y);
}
template <typename T, typename W, typename Q>
inline void Int(T &x, W &y, Q &z) {
  Int(x, y), Int(z);
}
const int N = 1e5 + 7;
const int inf = 1e9 + 7;
int solve() {
  int x_need, y_need;
  Int(x_need, y_need);
  int x, y;
  Int(x, y);
  int lcm = x / gcd(x, y) * y;
  int l = 1, r = 1e9, v = 1, both_need = x_need + y_need;
  while (l <= r) {
    int md = l + r >> 1;
    int both_rejects = md / lcm;
    int x_rejects = md / x - both_rejects;
    int y_rejects = md / y - both_rejects;
    int valid = md - (x_rejects + y_rejects + both_rejects);
    valid += min(x_need, y_rejects) + min(y_need, x_rejects);
    if (valid >= both_need)
      v = md, r = md - 1;
    else
      l = md + 1;
  }
  printf("%d\n", v);
  return 0;
}
int main() {
  int tests = 1, CaseNo = 0;
  while (tests--) {
    solve();
  }
  return 0;
}
