#include <bits/stdc++.h>
using namespace std;
int fabs(int a) { return a > 0 ? a : -a; }
int main() {
  int cnt1, cnt2, a, b;
  cin >> cnt1 >> cnt2 >> a >> b;
  int ans, ans1, ans2;
  int x;
  for (int i = 1; i < 10; i++)
    if ((a - 1) * i <= cnt1 && (a - 1) * (i + 1) >= cnt1) x = i;
  ans1 = a * x;
  ans1 += (cnt1 - (a - 1) * x);
  for (int i = 1; i < 10; i++)
    if ((b - 1) * i <= cnt2 && (b - 1) * (i + 1) >= cnt2) x = i;
  ans2 = b * x;
  ans2 += (cnt2 - (b - 1) * x);
  ans = max(ans1, ans2);
  cout << ans << endl;
  return 0;
}
