#include <bits/stdc++.h>
int setBit(int N, int pos) { return N = N | (1 << pos); }
int resetBit(int N, int pos) { return N = N & ~(1 << pos); }
bool checkBit(int N, int pos) { return (bool)(N & (1 << pos)); }
using namespace std;
int main() {
  long long int a, b, x, y, ans, temp, cnt;
  cin >> a >> b >> x >> y;
  if (a < b) {
    swap(a, b);
    swap(x, y);
  }
  ans = a / (x - 1) * x - 1;
  if (a % (x - 1) != 0) ans += a % (x - 1) + 1;
  if (ans / y - (ans / (x * y)) >= b) {
    cout << ans << endl;
    return 0;
  }
  temp = ans / y - (ans / (x * y));
  b -= temp;
  cnt = 0;
  for (ans = ans + 1;; ans++) {
    if (ans % y != 0) cnt++;
    if (cnt == b) break;
  }
  cout << ans << endl;
  return 0;
}
