#include <bits/stdc++.h>
using namespace std ;
int main()
{
int n , k ;
scanf("%d %d" , &n , &k) ;
int arr[n + 1] ;
for(int i = 0 ; i <= n ; i++) arr[i] = 1 ;
int moves = 0 , ini = k ;
if(k == 1 || k == n) printf("%d" , 3*n) ;
else
{
for(int i = 0 ; i < n ; i++)
{
if((k == 1 || k == n) && i != (n - 1))
{
moves = moves + abs(k - ini) + 1 + 1 + arr[k] ;
arr[k] = 0 ;
if(k == 1) k = ini + 1 ;
else k = ini - 1 ;
continue ;
}
if(i == (n - 1)) moves = moves + arr[k] + 1 ;
else moves = moves + arr[k] + 2 ;
if(arr[k - 1] != 0 && arr[k + 1] != 0)
{
if(arr[k - 1] <= arr[k + 1]) arr[k - 1] += arr[k] ;
else arr[k + 1] += arr[k] ;
}
arr[k] = 0 ;
if(k <= n/2) k-- ;
else k++ ;
}
printf("%d" , moves) ;
}
return 0 ;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQgOwoKaW50IG1haW4oKSAKewoJaW50IG4gLCBrIDsKCXNjYW5mKCIlZCAlZCIgLCAmbiAsICZrKSA7CglpbnQgYXJyW24gKyAxXSA7Cglmb3IoaW50IGkgPSAwIDsgaSA8PSBuIDsgaSsrKSBhcnJbaV0gPSAxIDsKCWludCBtb3ZlcyA9IDAgLCBpbmkgPSBrIDsKCWlmKGsgPT0gMSB8fCBrID09IG4pIHByaW50ZigiJWQiICwgMypuKSA7CgllbHNlCgl7CgkJZm9yKGludCBpID0gMCA7IGkgPCBuIDsgaSsrKQoJCXsKCQkJaWYoKGsgPT0gMSB8fCBrID09IG4pICYmIGkgIT0gKG4gLSAxKSkKCQkJewoJCQkJbW92ZXMgPSBtb3ZlcyArIGFicyhrIC0gaW5pKSArIDEgKyAxICsgYXJyW2tdIDsKCQkJCWFycltrXSA9IDAgOwoJCQkJaWYoayA9PSAxKSBrID0gaW5pICsgMSA7CgkJCQllbHNlIGsgPSBpbmkgLSAxI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