#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102c000000,102c000000")
using namespace std;
const int N = 3 * 1e6 + 10;
const int MOD = 1e9 + 7;
double const pi = acos(-1);
void fre() { freopen("in.txt", "r", stdin); }
int main() {
  long long n, x;
  scanf("%I64d%I64d", &n, &x);
  long long ans = 0;
  if (n % 2 == 0) {
    if (x > n / 2) x -= 2 * (x - n / 2);
    ans = (long long)(n - x) * 3;
  } else {
    ans = (long long)(n - 1) * 3;
  }
  printf("%I64d\n", ans);
}
