#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, X;
  cin >> N >> X;
  if (X == N / 2) {
    cout << 3 * X;
  } else if (X >= N / 2) {
    cout << 3 / 2 * X + N;
  } else {
    cout << (X + N) * X / (N - X) + N;
  }
  return 0;
}
