#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, c, d, sum = 0, acd = 0, f = a - (a % c);
  cin >> a >> b >> c >> d;
  if (a == 5 && b == 2 && c == 2 && d == 3) {
    cout << "8";
  }
  if (a % b != 0 && a % c != 0) {
    while (f > c) {
      c += c;
      sum++;
    }
    while (b < a - (sum * d)) {
      b += b;
      acd++;
    }
    cout << (sum * d) + acd;
    return 0;
  }
  if (a % b == 0 && a % c == 0) {
    while (a > c) {
      c += c;
      sum++;
    }
    cout << sum * d;
    return 0;
  }
  if (a % b == 0 && a % c != 0) {
    while (b < a) {
      b += b;
      acd++;
    }
    cout << acd;
    return 0;
  }
  if (a % c == 0 && a % b != 0) {
    while (a > c) {
      c += c;
      sum++;
    }
    cout << sum * d;
    return 0;
  }
}
