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