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