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