#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, X, ans;
  cin >> N >> X;
  double judge_N = (double)N / 2;
  if (X < judge_N) {
    ans = 4 * (N - X);
  } else if (X == judge_N) {
    ans = 3 * X;
  } else {
    ans = 4 * X;
  }
  printf("%d", ans);
}
