#include<iostream>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int result = 6 + (n - 2) * 3;//for num 1
	int mid = n / 2;
	if (n % 2 != 0)
		mid++;
	int index = 0;
	if (k > mid)
		index = n - k+1;
	else
		index = k;
	result += index - 1;
	cout << result;
	//system("pause");
	return 0;
}

#include<bits/stdc++.h>

using namespace std ;

int main () {

    long long int n , k  ,ans=0 , x ,y ,z ,t1,t2,t3;

    cin >> n >> k ;

    if (n==k){
        y=n-1 ;
    }
    else if (n/2>=k)
        y=k+n-2;
    else
        y=(n-k)+n-1 ;

    ans+=y+ n ;

    ans+=n+1 ;

    cout << ans ;

    return 0 ;
}

#include<iostream>
using namespace std;
int main(){
int x,k;
cin>>x>>k;
if(x-k>k-1){
	cout<<3*x+k-1;
}else{cout<<4*x-k;}

}

#include<iostream>
using namespace std;

int main() {
	int n, k;
	while (cin >>n >> k) {

		if (n == 2 && k == 2)
			cout << 6 <<endl;
		else {
			if (k <= (n /2))
				cout << (k - 1) + 6 + (n - 2) * 3 << endl;
			else
				cout << (n - k) + 6 +  (n - 2) * 3 << endl;
		}

	}
}

#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include <fstream>
#include <set>
#include <list>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define all(g) g.begin(),g.end()
#define allr(g) g.rbegin(),g.rend()
#define re(x)   return cout<<x,0
#define in(n)for(int i=0;i<n;i++)cin>>v[i];
#define loop(n)for(int i=0;i<n;i++)
#define matar 	ios_base::sync_with_stdio(false); cin.tie(NULL);
#define me(x,v) memset(x,v,sizeof(x))
#define endl '\n'
ll GCD(ll a, ll b){ return(b == 0) ? a : GCD(b, a%b); }
ll LCM(ll a, ll b)
{
	ll temp = GCD(a, b);

	return temp ? (a / temp * b) : 0;
}
int dx[4] = { 1, -1, 0, 0 };
int dy[4] = { 0, 0, 1, -1 };
ll oo = 1e18;
ll const M = 1e6, N = 2e5 + 7;
ll  n, sum, t, k;
int x, y, m,ans;
int a[501][501], b[501][501];
int main()
{
	matar

		cin >> n >> k;
	cout << n * 3 + min(n - k, k-1);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int sum=0,i,n,k;
	cin>>n>>k;
	if((k==1)||(k==n))
	{
		cout<<3*n;
		return 0;
	}
	if(k<=(n-k))
	{
		sum+=(3*k)-1;

		sum+=(n-k)*3;
		sum+=k;
		cout<<sum;
		return 0;
	}
	else
	{
		k--;
		sum+=(3*(n-k))-1;
		sum+=(k)*3;
		sum+=n-k;
		cout<<sum;
		return 0;
	}

}

#define _USE_MATH_DEFINES

#include <iostream>
#include <vector>
#include <algorithm>
#include<map>
#include<cmath>
#include<string>
#include<set>
#include<iterator>
#include<queue>
#include <math.h>

using namespace std;

int main() {
int n,k;
cin>>n>>k;

long long s=2*n+1,d=min(n-k,k-1)+n-1;
s+=d;

cout<<s;

}

#include <iostream>
#define N 5005

using namespace std;

int n,m;
int sum;

int main(int argc, char** argv)
 {
 	cin >> n >> m;
 	if(m <= ((n+1)/2))
 	sum = n+1 +n +n-1 +m-1;
 	else
 	sum = n+1 +n +n-m +n-1;
 	cout << sum;
 	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#pragma warning(disable : 4996)

int main()
{
	int n, k, steps = 0;
	scanf("%i %i", &n, &k);

	if (k <= (n >> 1))
		steps = k - 1;
	else
		steps = n - k;

	steps += (n << 1);
	steps += n;

	printf("%i", steps);
}

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

/*
ID : moreda
PROG : contest TEMPLATE-1
LANG : Microsoft Visual C++ 2017
*/
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <string>
#include <vector>

using namespace std;

typedef long double ld;
typedef long long ll;
typedef unsigned char byte;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef vector<int> vi;

#define ms(arr,val)                      memset(arr, val, sizeof(arr))
#define pb                               push_back
#define fo(iterator,first,before_last)   for(int iterator = first; iterator < before_last; ++iterator)
#define fr(iterator,first,before_last)   for(int iterator = before_last - 1; iterator >= first; --iterator)
#define mp(first,second)		         make_pair(first, second)
#define xx                               first
#define yy                               second
#define pi                               3.14159265358979323846264338327950
#define ee                               2.71828182845904523536028747135266

template<typename T, typename U> inline void amin(T &x, U y) { x = min(x, y); }
template<typename T, typename U> inline void amax(T &x, U y) { x = max(x, y); }

const long double eps = 1e-15;
const int maxN = 1 * 100000 + 10, mod = (int) 1e9 + 7;

int n, k;

int main()
{
	//ifstream cin("input.txt");
	ios_base::sync_with_stdio(0);
	cin >> n >> k;
	cout << 2 * n + 1 + (n - 1) + min(k - 1, n - k);

	return 0;
}

#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <utility>

using namespace std;

int main() {
	iostream::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, k, ans = 0;
	cin >> n >> k;
	if (n == 2) {
		ans = 6;
	}
	else {
		ans += 2 * n - 1 + min(k - 1, n - k) + 2 + (n - 1);
	}
	cout << ans;
	return 0;
}

#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<utility>
#include<vector>
#include<set>
#include<stack>
#include <sstream>
#include<queue>
typedef long long ll;
using namespace std;
const int N = 2e5 + 7;
int n, k, ans;
int main() {
	cin >> n >> k;
	if (n == k || k == 1)
		cout << n * 3;
	else {
		cout<< n * 3 + min((n - k), k -1);

	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
     ll i,j,k,l,m,n,g;

cin>>n>>k;
ll fuck=0;
//if(n==2)return cout<<6<<endl,0;
g=6+ min(n-k,k-1) + max(fuck,min(n-k-1,k-2))*3+ max(n-k,k-1)*3;
if(min(n-k,k-1)==0)g-=3;
//cout<<min(n-k,k-1)<<endl;
//cout<<max(fuck,min(n-k-1,k-2))*3<<endl;
//cout<<max(n-k,n-1)*3<<endl;
cout<<g<<endl;
}

#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;

int main()
{
   int n,k;
   long long int result=0;
   cin>>n>>k;
   if( (k-1) >= (n-k) ){
        result=result+(n-k);
       result=result+(3*n);
   }else{
       result=result+(k-1);
       result=result+(3*n);
   }
   cout<<result;
}

#include<iostream>
#include<sstream>
#include<vector>
#include<functional>
#include<algorithm>

using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int c = 0;
    c = c + n + n + 1;
    if(k-1 <= n-k){
        c = c + n + k - 2;
    }
    else{
        c = c + n + n - k - 1;
    }
    cout<<c;
    return 0;
}

#include<iostream>
#include<sstream>
#include<vector>
#include<functional>
#include<algorithm>

using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int c = 3*n;
    if(k-1 <= n-k){
        c = c + k - 1;
    }
    else{
        c = c + n - k;
    }
    cout<<c;
    return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	cout<<3*n+min(k-1,n-k);
}

//main2.cpp
//CodeforcesRound544(Div3)
//
//Created by Vladimir Khabarov on 12/03/2019.
//Copyright © 2019 Vladimir Khabarov. All rights reserved.

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, const char * argv[]) {

    // std::cout << "Enter input" << std::endl;

    int n, k;
    cin >> n;
    cin >> k;

    if (n == k || k == 1) {
        cout << 6 + (n - 2) * 3 << endl;
    } else {
        if (n - k < k) {
            cout << 6 + (n - 2) * 3 + (n - k) << endl;
        } else {
            cout << 6 + (n - 2) * 3 + k - 1 << endl;
        }
    }

    return 0;
}

#include <iostream>
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define psi std::pair<string,int>
#define pli std::pair<ll,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%I64d",&x)
#define prll(x) printf("%I64d ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vli std::vector<std::list<int>>
#define vlpi vector<list<pii>>
#define li std::list<int>
#define Endl printf("\n")
#define ma 1000000
#define mod 786433
#define FOR(i,a) for(int i=0; i<a; i++)

using namespace std;

int main()
{

    ll n  ; cin>>n ;
    ll k ; cin>>k;
    if (k-1>n-k) k=n-k+1 ;
    if (k>1) {
        cout << 2*k+k-1+n-1 + 2*(n-k ) +1 ; //  2*k+2*(k-1)+n-1+2*(n-k)  ;
    }
    else cout<< 3*n ;
}

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	uint32_t n, k;
	cin >> n >> k;

	std::uint32_t res = 0;
	std::uint32_t mid = n / 2;

	if (k <= mid)
		res = n * 3 + (k - 1);
	else
		res = n * 3 + (n - k);

	cout << res << endl;

	return 0;
}

#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
	int n, k;
	cin >> n >> k;
	cout << (min(n - k, k - 1) + 3 * n);
	return 0;
}

#include <iostream>
using namespace std;

main(){
    int n,k;
    cin>>n>>k;

    int r  = ((n-k)<(k-1))?(n-k):(k-1);

    cout<<r+3*n<<endl;
}

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;
int main()
{
    int n, i,j, k, l, r;
    cin >> n >> k;
    k--;
    k = k < n-1-k ? k : n-1-k;
    cout << 3*n+k;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int k;
    cin>>k;
    if(n==2)
    {
        cout<<"6";
    }
    else if(n>2)
    {
        if(k<=n-k)
        cout<<3*n+k-1;
        else
        cout<<4*n-k;
    }

}

#include <iostream>
using namespace std;
int min_moves(int,int);

int min_moves(int n, int k){
	if(n==k) return 3*k;
	else {
	    if((n/2)>=k) return (3*n+k-1);
	    else return (4*n-k);
	}
}

int main() {
	int n,k;
	cin>> n>> k;
	cout<< min_moves(n,k);
	// your code goes here
	return 0;
}

#include<iostream>
using namespace std;
int n,k;
int main()
{
	cin>>n>>k;
	if(k==1||k==n)
	cout<<2*n+n<<endl;
	else{
		int minn=n-k;
		if(k-1<minn)
		minn=k-1;
		cout<<2*n+minn+n<<endl;
	}
}

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define f first
#define s second
using namespace std;
int n , k ;
int main(){
	cin >> n >> k ;
	cout << 3 * n + min(n-k , k -1);

}

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n,k;
	long long ans;
	cin>>n>>k;
	if(n==2)ans=6;
	else if(k==1 || k==n)
	{
		ans=n*3;
	}
	else
	{
		ans=n*3+min(k-1,n-k);
	}
	cout<<ans;

}

#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;

int main()
{
	int n, k=0;
	cin >> n;
	cin>>k;
	long long int number = 2*n + 1;
		number += n - 1 + min(k - 1,n-k);
		cout << number;

	return 0;
}

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
#include<sstream>
#include<list>
#include<math.h>
#include<map>
#include<set>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<fstream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<cstring>
#include <deque>
#include<stack>
using namespace std;

#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define PI acos(-1.0)
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
long long GCDFast(long long a, long long b) { while (b)b ^= a ^= b ^= a %= b;  return a; }
#define SET(a) memset(a,-1,sizeof(a))
#define ALL_BITS ((1 << 31) - 1)
#define NEG_BITS(mask) (mask ^= ALL_BITS)
#define TEST_BIT(mask, i) (mask & (1 << i))
#define ON_BIT(mask, i) (mask |= (1 << i))
#define OFF_BIT(mask, i) (mask &= NEG_BITS(1 << i))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define MX 100010
#define pii pair<int,int>
#define LL long long
// UP, RIGHT, DOWN, LEFT, UPPER-RIGHT, LOWER-RIGHT, LOWER-LEFT, UPPER-LEFT
int dx[8] = { -1, 0, 1, 0, -1, 1,  1, -1 };
int dy[8] = { 0, 1, 0,-1,  1, 1, -1, -1 };

long long GCD(long long b, long long a)
{
	if (a == 0)
		return b;
	return GCD(a, b%a);
}
long long getLCM(long long a, long long b) {
	long long c = a / GCD(a, b);
	return b * c;
}
LL a[200005];

int main() {
	//freopen ("d:/Codejam/lazy_loading.txt","r",stdin);
	//freopen ("d:/Codejam/output.txt","w",stdout);
	LL n, i, j, k, temp, m;
	LL x, y, z, sum, test_case = 0, length, ans, test, l;
	string str;

	int c = 0, position;
	while (cin >> n>>k) {
		sum = n * 2 + 1;// stone remove, coin take, one plus for stone in last hole

		sum += n - 1;//move must be made

		sum += std::min(k - 1, n - k);

		cout << sum << endl;

	}

	return 0;
}

#include<iostream>
using namespace std;
int main()
{
    int n,p,t=0,i;
    cin>>n>>p;
    if(p<=n/2){
        t=6;
        for(i=p-1;i>=1;i--){
            t=t+4;
        }

        for(i=p+2;i<=n;i++){
            t=t+3;
        }
        }
        else{
            t=6;
        for(i=p+1;i<=n;i++){
            t=t+4;
        }

        for(i=p-2;i>=1;i--){
            t=t+3;
        }
        }
        cout<<t;
    return 0;
}

/*
 * @author : Kaustuk Rathod
 */
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fast_cin() ios_base::sync_with_stdio(0)
const int mod = 1e9+7;
using namespace std;

int main()
{
    fast_cin();
    ll n,k;
    cin>>n>>k;
    cout<<3*n+min(k-1,n-k)<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define  sci(x)   scanf("%d", &x)
#define  scl(x)   scanf("%lld", &x)
#define  scd(x)   scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //CODE TONOY
    ll n,p;
    cin >> n >> p;
    cout << (2 * n + 1) + (n - 1) + min(p - 1, n - p) << endl;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int N, K;

    cin >> N >> K;

    if (K == 1 || K == N)
         cout << N * 3 << '\n';
    else
    {
        int r = N - K;
        int l = K - 1;
        if (r < l)
        {
            cout << N * 3 + r << '\n';
            return 0;
        }
        else
        {
            cout << N * 3 + l << '\n';
            return 0;
        }

    }

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int N, K;

    cin >> N >> K;

    cout << N * 3 + min(N - K, K - 1);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int n,k,ans;
	cin >> n >> k;
	if (n == 2) printf("6");
	else
	{
		if (k == 1 || k == n) cout << n*3 << endl;
		else
		{
			int t = min(k,n-k+1);
		    ans = 6;
			ans += (t-2)*3;
			ans += t-1;
			ans += (n-t)*3;
			cout << ans << endl;
		}
	}
	//system("pause");
}

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{

    ios::sync_with_stdio(0);
    ll k,n;
    cin>>n>>k;
    cout<<3*n+min(k-1,n-k);
    return 0;
}

#include <iostream>

using namespace std;

int main()
{
    int n;
    int z;
    cin >> z >> n;
    int t=0;
    if (n<=z/2 )
        t=(2*n - 2)+ z - n +2*z +1;
    else
        t=(2*(z-n) )+ n +2*z ;
    cout << t;
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
using namespace std;
/*
vector <int> connect[300000];
int line[300000];
int main() {
	int N, M;
	scanf("%d", &N, &M);
	for (int i = 0; i < N; i++) {
		scanf("%d", line + i);
	}

}
*/
int n, m;
int main() {
	scanf("%d %d",&n,&m);
	int sum = 1 + n + n;
	sum += min(n + m - 2, n - 1 + n - m);
	printf("%d", sum);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    if(k!=n && k!=1){
        if(n-k>=k)
          cout << 3 * n + k - 1;
        else{
            cout<<3*n+n-k;
        }
    }

    else
    cout<<3*n;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int fun(int c,int n,int k){
   int ans=min(k,n-k+1);
    int ee=0;
        if(ans==k){
            for(;ans!=1;ans--){
                c+=2;ee++;
            }
            c+=2*(n-k)+ee;
        }else{ans=k;
            for(;k!=n;k++)
                {c+=2;ee++;}
            c+=2*(n-(n-ans+1))+ee;
        }
        return c;
}
int main(){
    int n,k,c;
    cin>>n>>k;
    if(k==1||k==n)
        cout<<3*n;
    else{
        c=n+2;
        cout<<fun(c,n,k);
    }
    return 0;
}

/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WaRNINGS*/
#include<bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = (1e-9);
typedef long long ll;
typedef unsigned long long ull;
#define flush fflush(stdout), cout.flush()
#define all(v) ((v).begin()),((v).end())
#define rall(v) ((v).rbegin()),((v).rend())
#define clr(v,idx) memset(v,idx,sizeof(v))
#define rep(i,n) for(int(i)=0;(i)<(int)(n);(i)++)
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define lcm(a,b) (a*(b/__gcd(a,b)))
#define P 1000000007
#define endl '\n'

const ll dx[] = {1,-1,0,0,1,-1,1,-1};
const ll dy[] = {0,0,1,-1,1,-1,-1,1};

void file() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
}

int main(int argc, char const *argv[])
{
	file();

	int n,k;cin>>n>>k;

	cout<< 3 * n + min(k-1,n-k);
}

#include <iostream>

using namespace std;

int n, k;

int main (){

      cin>>n;
      cin>>k;

      cout<<n*3 + min(n-k, k-1);

      return 0;
}

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <queue>
#include <map>
#include <string>
#include <vector>
#include <set>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define ll long long
#define chushihua(x,y) memset(x,y,sizeof x)
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const ll MAXX = 1000000 + 10;
const double PI = 3.14159265358979323846;
const ll mod = 1000000007;
int main() {
	int n, m;
	cin >> n >> m;
	if (m == 1 || m == n) {
		cout << n * 3 << endl;
	}
	else {
		int minn = min(m-1, n - m);
		int ans = minn + n * 3;
		cout << ans << endl;
	}
	return 0;
}

#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
using namespace std;
int n,m,v=1e8+9;
int main()
{
	scanf("%d%d",&n,&m);
	printf("%d\n",n*3+(n-m>m-1?m-1:n-m));
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n,k,ext;
	cin>>n>>k;
	int ans;
	if(n==2)
	{
	    ans=n+(n-1)+(n+1);
	}
	else if(n%2==0)
	{
	    if(k<n/2)
	    {
	        ext=k-1;
	    }
	    else if(k>(n/2)+1)
	    {
	        ext=n-k;
	    }
	    else
	    {
	        ext=(n/2)-1;
	    }
	    ans=n+(n-1)+(n+1)+ext;
	}
	else
	{
	    if(k<(n+1)/2)
	    {
	        ext=k-1;
	    }
	    else if(k>(n+1)/2)
	    {
	        ext=n-k;
	    }
	    else
	    {
	        ext=((n+1)/2)-1;
	    }
	    ans=n+(n-1)+(n+1)+ext;
	}
	cout<<ans;

	return 0;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pi pair<ll,ll>
#define mp make_pair
#define srtin1 cin.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );
#define strin2 getline(cin, text);
#define fi first
#define se second
#define pb push_back
#define mod (ll)1000000007
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mxn 311111
#define mxn2 1111111
#define test cout<<"vaibhav";
#define dd double
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
int main(){
    ll n, k;
    cin >> n >> k;
    ll ans = n;//uthana
    ll a = min(k-1, n-k);
    ll b = min(k,n-k+1);
    ans += (2*a + max(k-1,n-k));
        cout << ans + n + 1 << endl;
        return 0;
    //cout << ans << endl;
    //ans += (2*b + 1);
    //ll tmp = (a*(a+1))/2;
    //cout << ans << endl;
    //ans += (3*tmp + 2);
    //ans += max(k-1, n-k);
    cout << ans << endl;

}

// Problem : B. Nastya Is Playing Computer Games
// Contest : Codeforces - Codeforces Round #546 (Div. 2)
// URL : https://codeforces.com/problemset/problem/1136/B
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1000000007
#define hell2 1000000009
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll long long
#define ld long double
#define no_of_digits(n) floor(log10(n)) + 1
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define see(x) cout << #x << "=" << x << endl;
#define see2(x, y) cout << #x << "=" << x << "\t" << #y << "=" << y << endl;
#define see3(x, y, z) cout << #x << "=" << x << "\t" << #y << "=" << y << "\t" << #z << "=" << z << endl;
#define INF 1e9+5
#define LL_MAX 1e18+5

using namespace std;

const ld PI = acos((ld)-1);

ll modmult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll modmultbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=modmultbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;}
ll modadd(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll modsub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = modmult(r,n,p); n = modmult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}

int isPowerof2(ll x) { return (x && !(x & (x-1))); }

ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; }

bool isPerfectSquare(long double x) {long double sr = sqrt(x); return ((sr - floor(sr)) == 0); }

bool boundary(ll i,ll j,ll n, ll m){return (i>=0 && i<n && j>=0 &&  j<m);} //matrix boundary checking

ll ceil(const ll &a, const ll &b){return (a - 1)/b + 1;}
int lcm(int a, int b){return (a*b)/__gcd(a, b);}

string alpha="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};

// cout << fixed for removing e notation

bool comp2(const pair<int, int>&a, const pair<int, int>&b)
{
    if(a.second < b.second)
        return true;
    else if(a.second == b.second)
    {
        if(a.fi > b.fi) return true;
        else return false;
    }
    else return false;
}

bool prime[10000005];
void SieveOfEratosthenes(int n)
{
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1] = 0;
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
    }
}

int main()
{
	int n, k;
	cin >> n >> k;

	cout << 3*n + min(n-k, k-1) << "\n";
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll inf=(1ll<<61);
const int MX=3e5+9;
int n,k,ans;
int main(){
    cin>>n>>k;
    if(k==1||k==n){
        cout<<3*n<<endl;
        return 0;
    }
    k=min(k,n-k+1);
    ans=(k-1)*2+n-k   +   n+1;
    cout<<ans+n<<endl;
}

    #include<bits/stdc++.h>
    #include <iostream>
    using namespace std;
    #define ll long long
    #define ld double
    #define  pb push_back
    #define  ff(n) for(i=0; i<n; i++)
    #define mo 1000000007
    ll max(ll a,ll b){return (a>b)?a:b;}
    ll min(ll a,ll b){return (a<b)?a:b;}
    ll gcd(ll a,ll b)
        {
            while(1)
            {
                if(a==0)
                 return b;
                b%=a;
                if(b==0)
                 return a;
                a%=b;

            }
        }
    ll p2(ll k,ll n)
        {
            ll re=1;
            while(n)
            {
                if(n%2==1)
                 re=(re*k);
                k*=k;
                n/=2;
            }
            return re;
        }
    bool mm(vector<ll>a,vector<ll>b)
    {
        if(a[0]>b[0])
         return true;
        if(a[0]==b[0] &&a[1]>b[1])
         return true;
        return false;

    }
    int main()
    {
        ll n,k,m,i,j,t;
         t=1;
       // cin>>t;
        for(ll ii=0; ii<t;ii++)
        {
           cin>>n>>m;
           ll s=0;
           s+=3*n;
           // cout<<s<<" "<<min(n-m,m)-1<<endl;
            if(m!=1 && m!=n)
            s+=min(n-m+1,m)-1;
             cout<<s<<endl;

        }
        return 0;
    }

// Problem : B. Nastya Is Playing Computer Games
// Contest : Codeforces - Codeforces Round #546 (Div. 2)
// URL : https://codeforces.com/problemset/problem/1136/B
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1000000007
#define hell2 1000000009
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll long long
#define ld long double
#define no_of_digits(n) floor(log10(n)) + 1
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define see(x) cout << #x << "=" << x << endl;
#define see2(x, y) cout << #x << "=" << x << "\t" << #y << "=" << y << endl;
#define see3(x, y, z) cout << #x << "=" << x << "\t" << #y << "=" << y << "\t" << #z << "=" << z << endl;
#define INF 1e9+5
#define LL_MAX 1e18+5

using namespace std;

const ld PI = acos((ld)-1);

ll modmult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll modmultbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=modmultbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;}
ll modadd(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll modsub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = modmult(r,n,p); n = modmult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}

int isPowerof2(ll x) { return (x && !(x & (x-1))); }

ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; }

bool isPerfectSquare(long double x) {long double sr = sqrt(x); return ((sr - floor(sr)) == 0); }

bool boundary(ll i,ll j,ll n, ll m){return (i>=0 && i<n && j>=0 &&  j<m);} //matrix boundary checking

ll ceil(const ll &a, const ll &b){return (a - 1)/b + 1;}
int lcm(int a, int b){return (a*b)/__gcd(a, b);}

string alpha="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};

// cout << fixed for removing e notation

bool comp2(const pair<int, int>&a, const pair<int, int>&b)
{
    if(a.second < b.second)
        return true;
    else if(a.second == b.second)
    {
        if(a.fi > b.fi) return true;
        else return false;
    }
    else return false;
}

bool prime[10000005];
void SieveOfEratosthenes(int n)
{
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1] = 0;
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
    }
}

int main()
{
	int n, k;
	cin >> n >> k;

	int picked[n+1] = {0};
	int stones[n+1];

	for(auto &x: stones) x = 1;

	// ms(stones, -1);
	int moves = 0;

	if(k == 1)
	{
		stones[k+1]++;
		moves++;

		moves += 2;

		for(int i=2;i<n;i++)
		{
			moves += stones[i] + 1;
			moves++;
		}

		moves += stones[n] + 1;

		cout << moves << "\n";
	}
	else if(k == n)
	{
		stones[k-1]++;
		moves++;

		moves += 2;
		for(int i=k-1;i>1;i--)
		{
			moves += stones[i] + 1;
			moves++;
		}

		moves += stones[1] + 1;

		cout << moves << "\n";
	}
	else
	{
		if(k <= n/2)
		{
			stones[k+1]++;
			moves += 2;

			moves++;

			for(int i=k-1;i>1;i--)
				moves += stones[i] + 2;
			moves += stones[1] + 1;
			// see(moves);

			moves += k;
			for(int i=k+1;i<n;i++)
				moves += stones[i] + 2;
			moves += stones[n] + 1;

			cout << moves << "\n";
		}
		else
		{
			stones[k-1]++;
			moves += 3;

			for(int i=k+1;i<n;i++)
				moves += stones[i] + 2;
			moves += stones[n] + 1;

			moves += n-k+1;

			for(int i=k-1;i>1;i--)
				moves += stones[i] + 2;
			moves += stones[1] + 1;

			cout << moves << "\n";
		}
	}
}

#include<bits/stdc++.h>
#define  lld long long int
#include<vector>
#include<stack>

//set ->   s.insert(x)
//set ->   s.count(x)==0 => not present
//sort( vec.begin(), vec.end() );
//vec.erase( unique( vec.begin(), vec.end() ), vec.end() );
using namespace std;

int main()
{
	lld n,k;
	cin>>n>>k;

	lld l,r;
	l=k-1;
	r=n-k;
	if(k==1||k==n)
	{

		cout<<6+3*(n-2);exit(0);
	}
	if(r<l)
	{
		r--;
		if(r!=0)
		cout<<6+r*3+r+2+l*3-1;
		else cout<<7+3*l;

	}
	else
	{

		l--;
		if(l!=0)
		cout<<6+l*3+l+2+r*3-1;
		else cout<<7+3*r;

	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,l,l1,l2;
    cin>>n>>k;
    l1=n-k+1;
    l=min(l1,k);
    cout<<(n*3)+l-1<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,k;
	cin>>n>>k;long long int num2;long long int g=min((n-k),(k-1));
	long long int num=k-1; long long int count =0;
	if(k!=1&&k!=n){
	count=3*n+g;

//	num2=n-num; count+=(num2*(num2+1)/2)+(2*num2) +((num)*(num+1)/2)+(2*(num))-2;
}
    else if(k==1||k==n)
    {
    	count=3*n;
	}
	cout<<count;
}

#include<bits/stdc++.h>

using namespace std;

int main(){

	int n,k;

	cin>>n>>k;

	cout<<n*3+min(k-1,n-k);
}

#include<bits/stdc++.h>

using namespace std;

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	cout.tie(0);

	int n,k;

	cin>>n>>k;

	cout<<n*3+min(k-1,n-k);
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,k,i;
    cin>>n>>k;
    int count=0;
    if(k==2)
    {
        if(k==n)
            cout<<6;
        else
        {
            count=7;
            for(i=k+1;i<=n;i++)
                count+=3;
            cout<<count;

        }
    }
    else if(k<2)
    {
        count=6;
        for(i=k+2;i<=n;i++)
            count+=3;
        cout<<count;
    }
    else if(k>2 && k<n)
    {
        count=6;
        if(k<=n/2)
        {
            for(i=k-2;i>0;i--)
                count+=3;
            count+=k-1;
            for(i=k+1;i<=n;i++)
                count+=3;
            cout<<count;
        }
        else
        {
            for(i=k+2;i<=n;i++)
                count+=3;
            count+=(n-k);
            for(i=k-1;i>0;i--)
                count+=3;
            cout<<count;
        }
    }
    else
    {
            count=6;
            for(i=k-2;i>0;i--)
                count+=3;
            cout<<count;
    }
    return 0;
}

#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<set>
#define LL long long
#include<string.h>
#include<string>
#define LL long long
#define woqu(x) printf("woqu   %d\n",x)
int comp(int a,int b){
return a>b;
}
using namespace std;
int main(){
int num,index;
int sum=0;
cin>>num>>index;
if(index-1<num-index){
    sum+=(index-1)*3;
    sum+=(num-index)*3;
    sum+=index-1;
}else{
  sum+=(num-index)*3;
  sum+=(index-1)*3+(num-index);
}
cout<<sum+3<<endl;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pub push_back
#define pob pop_back

int main ()
{
	ll n,k;
	cin>>n>>k;
	if(k==1 || k==n)
	{
		cout<<n*3;
	}
	else
	{
		if(k>n/2)
		{
			k=n-k+1;
		}
		cout<<3*n+k-1;
	}

}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define V(a) vector<a>
#define f(i,n) for(ll i=0;i<n;i++)
#define arr_in(a,n) f(i,n) cin>>a[i]
#define arr_out(a,n); f(i,n) cout<<a[i]<<" ";cout<<endl;
bool isprime(int n)
{   if (n <= 1)  return false; if (n <= 3)  return true;
  	if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false;
    return true;
}
ll gcd(ll a,ll b)
{	if (a == 0)    return b; 	return gcd(b % a, a); }
ll lcm(ll a,ll b)
{	ll g=gcd(a,b); ll ans=(a*b)/g; return ans;	}
int main()
{
	ll n,k;
	cin>>n>>k;
	ll ans;
	ll min_ex=min(n-k,k-1);
	ans=min_ex+3*n;
	cout<<ans;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long int i64;

const int INF = (1 << 30);
const int MOD = 1e9 + 7;

const i64 INFL = (1LL << 62);
const i64 MODL = 1e9 + 7;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, k; cin >> n >> k;

	int moves = (min(k - 1, n - k)) + (3 * n);

	cout << moves << endl;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int n,k;
    cin >> n >> k;
    cout << 2 + min(n - k , k - 1)*2 + min(n - k , k - 1)*2 + max(n - k , k - 1) + (max(n - k , k - 1)* 2) + 1;

    return 0;
}

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()

#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b)	for(ll int i=a;i>=b;i--)
#define scan(i,b,k)  for(ll int i=0;i<b;i++) cin>>k[i];
#define show(i,b,k)	for(ll int i=0;i<b;i++) cout<<k[i]<<" ";
#define scanM(i,j,b,b1,k)	for(ll int i=0;i<b;i++)for(ll int j=0;j<b1;j++) cin>>k[i][j];
#define showM(i,j,b,b1,k)for(ll int i=0;i<b;i++){for(ll int j=0;j<b1;j++) cout<<k[i][j]<<" ";cout<<"\n";}

#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
	{
		ll int n,k;
		cin>>n>>k;
		ll int ans=n+min(k,n+1-k)-2+n;
		if(k==1 || k==n)
			cout<<ans+(n+1)<<endl;
		else
		{
			//cout<<ans<<" ";
			cout<<ans+n+1<<endl;
		}

	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
   int a,b;
   cin>>a>>b;
   int ans=0;

   if(a==b)
   {

   ans+=a*3;

   }
   else
   {
        ans+=a*3;
   ans+=min(a-b,b-1);

   }

   cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){
    ll n, i, j, k, ans = 1, mx = 1, sum;

    cin >> n >> k;

    mx = min(n - k, k - 1);
    ans = (n * 3) + mx;

    cout << ans << endl;

    return 0;
}

#include <iostream>

using namespace std;
int main()
{
    int n, k;

    cin >> n >> k;
    int sum = n;

    if(k == 1 || n == k){
        sum += n - 1 + n + 1;
        cout << sum << endl;
        return 0;
    }

    if(k - 1 < n - k)
        sum += n - 1 + k - 1 + n + 1;
    else
        sum += n - 1 + n - k + n + 1;

    cout << sum << endl;

    return 0;
}

#include <bits/stdc++.h>
#define sqr(a) ((a)*(a))
#define rsz resize
#define forr(i,a,b) for(int i=(a);i<(b);i++)
#define forn(i,n) forr(i,0,n)
#define dforn(i,n) for(int i=n-1;i>=0;i--)
#define forall(it,v) for(auto it=v.begin();it!=v.end();it++)
#define foreach(i, v) for(auto i:v)
#define sz(c) ((int)c.size())
#define zero(v) memset(v, 0, sizeof(v))
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fst first
#define snd second
#define PI 3.1415926535897932384626

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main()
{
	// agregar g++ -DREJUNTE en compilación
	#ifdef REJUNTE
		freopen("input", "r", stdin);
		// freopen("output","w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll n, k;

	cin>>n>>k;

	if(k==1 || k==n)
		cout<<n*3;
	else
		cout<<n+n+1+n-1+min(k-1, n-k);
	return 0;
}

#include<bits/stdc++.h>

using namespace std;
#define int long long
#define all(x) x.begin(),x.end()

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    if (n == 2){
        return cout << 6, 0;
    }
    if (k == 1 || k == n){
        k = 1;
        cout <<  6 + (n - k -1) * 3;
    }
    else {

        int ans = 6 + (k - 2) * 3 + k - 1 + (n - k) * 3;
        k = n - k + 1;
        int ans1 = 6 + (k - 2) * 3 + k - 1 + (n - k) * 3;
        cout << min(ans, ans1);
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int
main(int argc, char const *argv[])
{
	int n, k, steps = 0;
	cin >> n >> k;
	if(n == 2){
		cout << "6" << endl;
		return 0;
	}
	if (k <= n/2){
		steps = k + 6;
	} else {
		steps = n - k + 7;
	}
	for(int i = 2; i < n; ++i){
		steps += 3;
	}
	--steps;

	cout << steps << endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{

long long i,j,k,n;
cin>>n>>k;
if(n==k||k==1)
	cout<<3*n<<endl;
else
{
	if(k<=(n-k))
	cout<<3*n+k-1;
	else
	cout<<3*n+n-k;
	cout<<endl;
}

}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;

    int sum=0;
    if(k<=ceil(1.0*n/2))
    sum+=3*n+k-1;
    else
    sum+=3*n+n-k;

    cout<<sum<<endl;
    return 0;
}

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;

    int distanceToLast = min(K - 1, N - K);

    int moveAfterGot = N - 1;
    int actionToGot = N * 2 + 1;
    int justMove = distanceToLast;

    cout << moveAfterGot + actionToGot + justMove << endl;

    return 0;
}

#include<iostream>
#include<string>
#include<string.h>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstdlib>
#include<vector>
#include<set>
#include<deque>
#include<queue>
#include<math.h>
#include<chrono>
#include<list>
#include<random>
#include<bitset>
#include<assert.h>
#include<ctime>
#include<cstdio>
using namespace std;
ifstream fi("test.txt");
ofstream fo("out.txt");
#define fast_input() {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
#define ll long long
#define For(i,n) for (int(i) = 0; (i)<(n); (i)++)
#define For1(i,n) for (int(i) = 1; (i) <= (n); (i)++)
#define Forlr(i,l,r) for (int(i) = (l); (i) <= (r); (i)++)
#define Forrl(i,r,l) for (int(i) = (r); (i) >= (l); (i)--)
#define All(a) a.begin(), a.end()
#define pb push_back
#define pp pop_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265
#define putno return cout <<"NO", 0;
#define putyes return cout <<"YES", 0;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef map<int, int> mii;
//const ll MOD = 1e9 + 7;
const ll base = 269;
const ll ool = LLONG_MAX;
const int ooi = 1 << 30;
const int N = 1e5 + 5;
//DSU
/*
int p[ N], r[N];
void init(int n) {
	For(i, n) {
		p[i] = i;
	}
}
int get(int x) {
	if (p[x] != x) {
		p[x] = get(p[x]);
	}
	return p[x];
}
bool uni(int x, int y) {
	x = get(x); y = get(y);
	if (x == y) {
		return false;
	}
	if (r[x] >= r[y]) {
		p[y] = x;
	}
	else {
		p[x] = y;
	}
	if (r[x] == r[y]) {
		r[x]++;
	}
	return true;
}
*/

// So mu
/*
int power(int x, unsigned int y, int p)
{
	int res = 1; // Initialize result

	x = x % p; // Update x if it is more than or
	// equal to p

	while (y > 0)
	{
		// If y is odd, multiply x with result
		if (y & 1)
			res = (res*x) % p;

		// y must be even now
		y = y >> 1; // y = y/2
		x = (x*x) % p;
	}
	return res;
}
*/

// ReadHexa
/*
bitset<16400> b[4101];
void readHexa()
{
	For(i, n)
	{
		string st;
		cin>> st;
		For(j, m/4)
		{
			int x;
			if (st[j] >= 'A' && st[j] <= 'F')
				x = st[j] - 'A' + 10;
			else x = st[j] - '0';
			for (int k = 4; k; --k, x >>= 1)
				b[i][j * 4 + k] = x & 1;
		}
	}
}
*/

// nChoosek
/*
ll nChoosek(ll n, ll k)
{
	if (k > n) return 0;
	if (k * 2 > n) k = n - k;
	if (k == 0) return 1;

	ll result = n;
	for (ll i = 2; i <= k; ++i) {
		result *= (n - i + 1);
		result /= i;
	}
	return result;
}
*/

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
MIKUNO - 15/02/1999
*/
int n, m, k, t, cnt, rs1, q;
//ll n, m, q, k, pos, t, cnt, rs1, check;
ll maxx = -1e9, minn = 1e9;
const int maxn = 6;
const ll MOD = 1e9;
int rs;
int a[5005];
int main()
{
	fast_input();
	cin >> n >> k;
	rs = 3;
	int l = k - 1, r = n - k;
	if (l < r) swap(l, r);
	rs += 4 * r + 3 * l;
	cout << rs;
}

#include<bits//stdc++.h>
using namespace std;
int main(){
   int n,k;
   cin>>n>>k;
   if(k==n || k==1){
    cout<<n*3;
   }
   else{
    int p=k-1;
    int t=n-k;
    if(p<=t){
        int r=n*3+p;
        cout<<r;
    }
    else{
        int r=n*3+t;
        cout<<r;
    }
   }
}

// ==================
// author : chhokmah
// website : http://blog.chhokmah.top/
// create time : 18/08/19 12:34
// ==================
#include <bits/stdc++.h>
using namespace std;
int n, k, ans;
int calc(int x, int y) {
  int res = 6; res += 3 * (x - 2) + (x - 1); res += 3 * (y - 1);
  return res;
}
int main() {
  cin >> n >> k;
  if (n == 2) { cout << 6 << endl; return 0; }
  if (k == 1 || k == n) { ans = 6; ans += 3 * (n - 2); cout << ans << endl; return 0; }
  ans = min(calc(k, n - k + 1), calc(n - k + 1, k));
//  if (k == 2 || k == n - 1) ans --;
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define __FastIO                                                               \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);
#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)
#define D cout << "ok" << endl;
#define _(x) cout << #x << "->" << x;
#define _n cout<<endl;
#define _s cout<<" ";
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define FIN freopen("in", "r", stdin);
#define FOUT freopen("out", "w", stdout);
#define f first
#define s second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<db, db> pdd;
template <typename T> using ordered_set = tree<T, null_type, less<T>,
                            rb_tree_tag, tree_order_statistics_node_update>;

int main()
{
	__FastIO;
#ifndef ONLINE_JUDGE
	FIN FOUT
#endif
	int n, k;
	cin >> n >> k;
	int mini = INT_MAX;
	int ans;
	if (n == 1)
	{
		cout << 1 << endl;
		return 0;
	}
	if (n == 2)
	{
		cout << 6 << endl;
		return 0;
	}
	if (k == n)k = 1;
	ans =3 + (n - 1) * 2 +min( (k - 1) * 2 + (n - k),(k-1)+(n-k)*2);

	cout << ans << endl;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <string>
#include <memory>
#include <cmath>
#include <math.h>
#include  <iomanip>
using namespace std;
void file() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
}
#define all(a) a.begin(), a.end()
#define gg ios_base::sync_with_stdio(0); cin.tie(0)
#define ll long long
#define lld long double
const lld eps = 1e-6;
const int A_SIZE = 1e5 + 5;
const long long INF = 1e9, MOD = 1e9 + 7;

int main() {
	gg;
//	file();
	int n, k;
	cin >> n >> k;
	int answer = min(n - k, k - 1);
	answer += 3 * n;
	cout << answer;
}

#include <vector>
#include <ctype.h>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <string>
#include <map>
#include <fstream>
#include <conio.h>
#include <cstdio>
#include <random>
#include <chrono>
#include <windows.h>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	if (k == n || k == 1) {
		cout << (n * 2) + n << endl;
	} else {
		int k1 = n - k;
		if (k - 1 > k1) {
			cout << k1 * 4 + k * 2 + k << endl;
		}
		if (k - 1 < k1) {
			k--;
			k1++;
			cout << k * 4 + k1 * 2 + k1 << endl;
		}
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
vector<int> A[1001],B[1001];
int ar[1001][1001],arr[1001][1001],socanh[200010],sodinh[200010],up,ngua;
int kt=0,sl,sl1;
long long  n,m;
int main()
{
    int k;
    cin>>n>>k;
    cout<<3*n+min((int)((int)n-k),k-1);

}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<cmath>
using namespace std;

int n,k,ans;

int main()
{
    scanf("%d%d",&n,&k);
    ans = n * 3 + min(k - 1, n - k);
    printf("%d\n",ans);
    return 0;
}

#if 1
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
#define ff first
#define ss second
using namespace std;

int main() {
	int n, pos;
	cin >> n >> pos;
	int res = 6;
	if (pos == 1 || pos == n) {
		res += 3 * (n - 2);
	}
	else {
		int m = min(pos - 1, n - pos);
		res += m + 3 * (n - 2);
	}
	cout << res;
	return 0;
}

#endif

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,k,ans=0;
    cin>>n>>k;

    //ll x=max(n-k,k);
    //ans+=x*3;
    ll y=min(n-k,k-1);
    //ans+=y*3+x;

    cout<<n*3+y<<endl;

    return 0;
}

#include <algorithm>
#include <vector>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
#include <iostream>

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define debug printf("If you see this while scrolling you have been visited by smart debugger. Good luck and no errors will come to you.");
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);

// Solution

int main() {
    int n, k;
    cin >> n >> k;

    if (k == 1) {
        cout << 3 * n << endl;
    } else if (k == n) {
        cout << 3 * n << endl;
    } else {
        if (k > n / 2) {
            int dist = k - n / 2;

            k = (n + 1) / 2 - dist + 1;
        }

        cout << 3 * k + k - 1 + 3 * (n - k) << endl;
    }

}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	cin >> n;
	int k;
	cin >> k;

	cout << 3 * n + min((k - 1), (n - k));

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;

int main()
{
    int n, k;
    cin >> n >> k;
    if (k == 1 || k == n)
        cout << 6 + (n - 2) * 3 << endl;
    else
    {
        k = min(k, (1 + n - k));
        cout << 6 + (k - 2) * 3 + (k - 1) + (n - k) * 3 << endl;
    }

    return 0;
}

/****************************** بسم الله الرحمن الرحيم ************************/
/*---------------------------------------------------------------------*/
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#define ordered_set tree<pair<int, int>, null_type,less<pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define compare bool operator <
#define main int main()
#define sf(n) scanf ("%d", &n)
#define pf(n) printf ("%d", n)
#define sfl(n) scanf ("%lld", &n)
#define pfl(n) printf ("%lld", n)
#define pfnewline() printf("\n")
#define pfspace() printf(" ")
#define mem(x,y) memset( (x), (y), sizeof(x) )
#define max3(a,b,c)   max(a , max(b,c) )
#define min3(a,b,c)  min(a, min(b,c) )
#define Ex 2.718281828
#define pi acos(-1.0)
#define toDecimal(n) fixed<< setprecision(n)
#define rep1(i, n) for(int i = 1; i<=n;i++)
#define rep(i, n) for(int i = 0; i<n;i++)
#define sfc(ch) scanf("%c",&ch)
#define sfs(ch) scanf("%[^\n]%*c", ch);

const ll mxn = 1e5+3;

/** ---8 moves --- **/
//int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
//int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};

/** ---4 moves--**/
//int dx[] = {-1,0,0,1};
//int dy[] = {0,-1,1,0};

using namespace __gnu_pbds;
using namespace std;

//ll lcm(ll a, ll b)  return a/__gcd(a,b)*b;
//ll bigmod(int a, ll b) { if(b == 0) return 1% mod;    ll x = bigmod(a,b/2  );    x = (x * x) % mod;    if(b % 2 == 1) x = (x*a)% mod;   return x;}
string toString(int A)
{
    stringstream ss;
    ss<<A;
    string tmp;
    ss>>tmp;
    return tmp;
}

main
{
    int n,k;
    cin >> n >> k;
    int ans = n*3;
    cout << min( (k-1),(n-k) )+ans << endl;

}

#include <bits/stdc++.h>
using namespace std;

int main(){
     ios_base::sync_with_stdio(false);
     cin.tie(NULL); cout.tie(NULL);
     int N, K; cin >> N >> K;
     cout << N+1+N+N-1+min(N-K, K-1);
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
int main() {
	//ios_base::sync_with_stdio(0), cin.tie(0);

    int n,k; cin>>n>>k;
    //int ara[n+1]={1};

    if(n==2) cout<<"6\n";

    else if(k==1 or k==n) cout<<(n-2)*3+4+2<<endl;

    else
    {
        if(n==3)
            cout<<"10\n";
        else
        {
            int m;
            if(k!=n/2 and n%2==0) m=min(k,n-k);
            else if(k!=((n/2)+1) and n%2!=0) m=min(k,n-k);
            else m=k;

            cout<< 2+(m-1) + 4 + ((n-2)*3)<<endl;
        }
    }
    return 0;
}

#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main (){
    int n,m;cin>>n>>m;
    if (n==m||m==1) {cout<<6+(n-2)*3; return 0;}
  if (n%2==0)
    {if(m%2==0)
    cout<<6+(n-2)*3+min(n-m-1,m-1);
    else
    cout<<6+(n-2)*3+min(n-m,m);}
    if(n%2!=0)
    {
    if(m%2==0)
    cout<<6+(n-2)*3+min(n-m,m);
    else {if(m!=n)
    cout<<6+(n-2)*3+min(n-m-1,m-1);
     else  cout<<6+(n-2)*3+n;
    }}
    return 0;
}

#include <bits/stdc++.h>
#define ANONYMOUS_XTRM ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define INF 1000000
#define EB emplace_back
#define PB push_back
#define PF push_front
#define INS insert
#define MP make_pair
#define F first
#define S second
#define PII pair<int,int>
#define PLL pair<long long ,long long>
#define PLI pair<long long , int>
#define PIL pair<int ,long long>
#define PIPII pair<int , pair<int,int> >
#define PLPLL pair<long long , pair<long long, long long> >
#define square(a) (a)*(a)
#define SZ(a) ((int)(a.size()))
#define FOR(i, n) for (ll i = 0; i <ll(n); i++)
typedef int i;
typedef float f;
typedef char c;
typedef double d;
typedef long long ll;
typedef unsigned long long ut;
typedef long double ld;
using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    int xxx=0;
    if(n>k){
        xxx=n;
    }
    else if(k>n){
        xxx=k;
    }
    if(n==k){
        cout<<n+k+n<<endl;
    }
    else{
        cout<<n+k+(xxx*2)-1<<endl;
    }
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    if(n==2)
    cout<<6;
    else
    {

         if(k==1 || k==n)
         {
             cout<<3*n;
         }
         else{
             cout<<(2+3*(n-k)+n-k+1+3 +3*(k-2)-1);
         }

    }
    return 0;
}

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
	int n,p,m=0;
	cin>>n>>p;
	if((n-p)>=p )m=n*2+n+p-1;
	else if (p==n)m=n*3;
	else m=m=n*2+n+(n-p)-1;
	cout<<m<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
int find(int n)
{int ans=0;
    ans=n*2+n-1;
    return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,k;
cin>>n>>k;
if(k==1||k==n)
{
   int ans=find(n-2)+6;
    ans+=1;
   cout<<ans<<endl;
    return 0;
}
int x=find(k)+k+1;
x+=find(n-k);
int ans=x;
int y=find(n-k)+n-k+1;
y+=find(k);
ans=min(ans,y);
cout<<ans<<endl;
    return 0;
}

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

/*
                        author Mahmoud Tarek
                        --------------------
keep it simple gcc just accept my solution :) it is flow less good bye ....
dear overflow don't be sad /// in case of any error we just still friend :)
dear greedy don't be shy i will find you like it or not just leave the problem (;
finally dear time try to be good for the sake of solving the problems );
                             *******
                      Test Case --- // --- AC
                           Menofia FCI
                              Egypt
*/

#include <bits/stdc++.h>

using namespace std ;

#define sz(v) (ll)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define PI acos( -1.0 )
#define c_b fflush(stdin);

void File_input() {
    freopen( "in.txt", "r", stdin ) ;
    freopen( "out.txt", "w", stdout ) ;
}

void FastInputOutput() {
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

int n , k , ans ;

int main() {
    scanf("%d%d" , &n , &k );
    ans = ( 3 * n - 1 ) + k ;
    if( n == 2 )
    {
        ans -= 1 ;
    } else if( n == k ){
        ans -= 2 ;
    }
    printf("%d" , ans ) ;

    return 0 ;
}

#include <bits/stdc++.h>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
#define pb push_back
#define st first
#define nd second
#define paint pair<int,int>
#define pachar pair<int,char>
#define mp make_pair
using namespace std;

int main()
{
     BOOST;
     int n,k;
     cin>>n>>k;
     if (k>n/2)
     {
         k=(n-k)+1;
     }
     int poruszenia=(k-1)+(n-1);
     int rozbicie=n;
     int kamienie=k+(n-k);
  if (k==1 || k==2)kamienie++;
  //cout<<poruszenia<<" "<<rozbicie<<" "<<kamienie<<" "<<k<<"\n";
     cout<<poruszenia+rozbicie+kamienie;
    return 0;
}

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

int n,k;
int a[5001];
bool chk[5001];
int main() {
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%d%d",&n,&k);
	k=min(k,n+1-k);
	fup(i,1,n,1)a[i]=1;
	int ans=0;
	while(k>1)
	{
		chk[k]=1;
		ans+=a[k]+2;
		a[k+1]+=a[k];
		a[k]=0;
		k--;
	}
	chk[k]=1;
	ans+=a[k]+1;
	a[k+1]+=a[k];
	a[k]=0;
	while(chk[k])
	{
		ans++;
		k++;
	}
	while(k<=n)
	{
		ans+=a[k]+2;
		k++;
	}
	printf("%d",ans-1);
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>

using namespace std;

int main()
{
	//ifstream cin("input.txt");
	int n, k;
	__int64 sum = 0;
	cin >> n >> k;
	if (n == 2)
	{
		cout << 6;
		return 0;
	}
	else
	{
		sum = 6;
		if (k == n - 1)
		{
			sum += n - 1;
			sum += n - 2;
		}
		else if (k == 2)
		{
			sum += n - 1;
			sum += n - 2;
		}
		else if (k==1)
		{
			sum += n - 2;
			sum += n - 2;
		}
		else if (k == n)
		{
			sum += n - 2;
			sum += n - 2;
		}
		else if ((n-k)<(k-1))
		{
			sum += (n - k - 1)*2;
			sum += (n - k - 1);
			sum += n - 1;
			sum += k - 1;
		}
		else
		{
			sum += (k - 2) * 2;
			sum += (k-2);
			sum += n - 1;
			sum += (n-k);
		}
		sum += n-2;
	}
	cout << sum;

	//system("pause");
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int
main(int argc, char const *argv[])
{
	int n, k, steps = 0;
	cin >> n >> k;
	if(n == 2){
		cout << "6" << endl;
		return 0;
	}
	if (k <= n/2){
		steps = k + 7;
	} else {
		steps = n - k + 7;
	}
	for(int i = 2; i < n; ++i){
		steps += 3;
	}
	--steps;

	cout << steps << endl;

	return 0;
}

#include<bits/stdc++.h>
#define LL  long long
#define pb push_back
using namespace std;
int main()
{
    int n,k;
    int b;
    cin>>n>>k;

    int c = 0;

    if(n>k){
        c = k-1;
    }

    cout<<(n*3) + c;

}

#include <iostream>

using namespace std;

int main()
{
	int n;
	int k;
	cin>>n;
	cin>>k;
	int a;
	if (k==1 or k==n)
	{
		a=n*3;
	}
	else if (k<(n-k))
	{
		a=5+k+(n-2)*3;
	}
	else
	{
		k=n-k+1;
		a=6+k+(n-2)*3;
	}
	cout<<a<<endl;

	return 0;
}

#include<bits/stdc++.h>

using namespace std;
#define int long long
#define all(x) x.begin(),x.end()

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    if (n == 2){
        return cout << 6, 0;
    }
    if (k == 1 || k == n){
        k = 1;
        cout <<  6 + (n - k -1) * 3;
    }
    else {

        int ans = 6 + (k - 2) * 3 + k - 1 + (n - k) * 3;
        k = n - k - 1;
        int ans1 = 6 + (k - 2) * 3 + k - 1 + (n - k) * 3;
        cout << min(ans, ans1);
    }
    return 0;
}

#include<bits/stdc++.h>
#define ll long long int
#define fast std::ios::sync_with_stdio(0)
using namespace std;
int main()
{
	fast;
	ll n,k;
	cin>>n>>k;
	ll ans=0;
	ans=6+(n-2)*3+(k-1);
	cout<<ans<<"\n";
	return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
int main (){
    int n,m;cin>>n>>m;
    if(n%2!=0 ||n==2 )
    cout<<6+(n-2)*3;
    else cout<<6+(n-2)*3+1;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
   int a,b;
   cin>>a>>b;
   int ans=0;

   if(a==b)
   {

   ans+=a*2;
   ans+=a;
   }
   else
   {
        ans+=a*2;
   ans+=b-1+a;
   }

   cout<<ans<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,ans=0;
    cin>>a>>b;
    int ar[a+1];

    if(b==1 || b==a)
    {
        cout<<a*3<<endl;
    }
    else
    {
        cout<<(a*3)+1<<endl;
    }

    return 0;
}

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

#include <bits/stdc++.h>

using namespace std;
int n,k;
int main()
{
    cin>>n>>k;
    if(k<=n/2) cout<<(n-k+1)*3-1+n-k+1+3*(k-1);
    else cout<< k*3-1+k+(n-k)*3;
    return 0;
}

#include <iostream>

using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    int ans = 6;
    if (n == 2) {
        cout << 6;
        return 0;
    }
    if (k == 1 || k == n) {
        cout << ans + (n-2)*3;
        return 0;
    }
    ans += (k - 2)*3;
    ans += (k-1);
    ans += (n-k)*3;
    cout << ans;
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
const ll MOD=1e9+7;
using namespace std;
const int maxn=2e5+5;
int a[105],b[105];

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int ans=0;
    if(k==1||k==n)
    {
        printf("%d\n",3*n);return 0;
    }
    k=min(k,n-k);
    printf("%d\n",3*n+k-1);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    if(k==1 || k==n)
    {
    	cout<<3*n;
	}
	else
	{
		cout<<3*n+1;
	}

}

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define sd second
#define fst first
#define lp(i,n) for(int x=i;x<n;x++)
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define maxn 100010
#define inf 0x3f3f3f3f
bool vs[2001][2001];
int a[200005];
int n,m,v,k,mx,res,x,c;
LL ans;
int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin>>n>>k;
    if(k%2)cout<<3*n<<endl;
    else cout<<3*n+1<<endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,m,count=0,t;
    cin>>n>>m;
    if(n%2==0&&m!=1)
    {
      if(m<=n/2)
      {
        if(m!=1)
        {
         t=m;
       count=count+6;
       count=count+t*3;
       count=count+m-1;
       count=count+(n-m)*3;
        }
        else if(m==1)
        count=count+n*3;
      }
      else if(m>n/2)
      {
        t=n-m;
        m=1+t;
        if(m!=1)
        {
         t=m;
       count=count+6;
       count=count+t*3;
       count=count+m-1;
       count=count+(n-m)*3;
        }
         else if(m==1)
        count=count+n*3;
      }
    }
    else if(n%2!=0&&m!=1)
    {
        if(m<=(n+1)/2)
      {
        if(m!=1)
        {
         t=m;
       count=count+6;
       count=count+t*3;
       count=count+m-1;
       count=count+(n-m)*3;
        }
        else if(m==1)
        count=count+n*3;
      }
      else if(m>(n+1)/2)
      {
        t=n-m;
        m=1+t;
          if(m!=1)
        {
         t=m;
       count=count+6;
       count=count+t*3;
       count=count+m-1;
       count=count+(n-m)*3;
        }
        else if(m==1)
        count=count+n*3;
      }
    }
    else if(m==1)
    count=count+n*3;
    cout<<count;
}

#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)		memset(v, d, sizeof(v))
const double EPS = 1e-8;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int>P;
const ll mod = 1000000007;
int dx[] = { 0, 0, -1, 1, 1, 1, -1, -1 };
int dy[] = { 1, -1, 0, 0, 1, -1, -1, 1 };
const int N = 500001;
#define endl '\n'
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
void stop(){
#ifndef ONLINE_JUDGE
	system("pause");
#endif
}
struct point{
	double x, y;
};
ll gcd(ll a, ll b){ if (a < 0)a *= -1; if (b< 0)b *= -1; return !b ? a : gcd(b, a % b); }
ll fixMod(ll a, ll b){ return ((a%b) + b) % b; }
double triangle_area(int x1, int y1, int x2, int y2, int x3, int y3) {
	return abs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)) / 2.;
};
ll dis(point a, point b) {
	ll x = a.x - b.x, y = a.y - b.y;
	return x * x + y * y;
}
double traingleArea(double a, double b, double c) {
	double s = (a + b + c) / 2.0;
	return sqrt(s * (s - a) * (s - b) * (s - c));
}
double circleArea(double r) {
	return acos(-1) * r * r;
}
ll power(ll x, ll y)
{
	if (y == 0)return 1;
	if (y == 1)return x;
	ll r = power(x, y / 2) % mod;
	return r%mod*r%mod*power(x, y % 2) % mod;
}
int main(){
	fast
		ll n, k;
	cin >> n >> k;
	if (k == n || k == 1){
		cout << 3 * n << endl;
	}
	else {
		ll mn = min(k, n - k);
		ll mx = max(k, n - k);
		ll ans = mn * 3+mn;
		ans += mx * 3 ;
		if (mn == mx)ans--;
		cout << ans << endl;
	}
	stop();

	return 0;
}

#include <iostream>
#include<iostream>
#include<vector>
#include<algorithm>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
#include <queue>
using namespace std;

#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w",stdout)

int main(int argc, char* argv[])
{
#ifdef LOCAL
	FIN;
	FOUT;
#endif
	int n, k;
	cin >> n >> k;
	int ans = 0;

	//if (k == n || k == 1)
	//{
	//	ans++;
	//}
	if ( n/2 <= k)
	{
		k = n - k;
	}
	if (k == 0)
	{
		k = 1;
	}
	ans += n + k - 1 - 1;
	ans++;

	ans += n * 2;
	cout << ans << endl;

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,k,i;
    cin>>n>>k;
    int count=0;
    if(k==2)
    {
        if(k==n)
            cout<<6;
        else
        {
            count=8;
            for(i=k+1;i<=n;i++)
                count+=3;
            count--;
            cout<<count;

        }
    }
    else if(k<2)
    {
        count=6;
        for(i=k+2;i<=n;i++)
            count+=3;
        cout<<count;
    }
    else
    {
        count=6;
        for(i=k-2;i>0;i--)
            count+=3;
        count+=k;
        for(i=k+1;i<=n;i++)
            count+=3;
        count--;
        cout<<count;
    }
    return 0;
}

#include <iostream>
#include<iostream>
#include<vector>
#include<algorithm>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
#include <queue>
using namespace std;

#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w",stdout)

int main(int argc, char* argv[])
{
#ifdef LOCAL
	FIN;
	FOUT;
#endif
	int n, k;
	cin >> n >> k;
	int ans = 0;

	//if (k == n || k == 1)
	//{
	//	ans++;
	//}
	if ( n/2 <= k)
	{
		k = n - k + 1;
	}

	ans += n + k - 1 - 1;
	ans++;

	ans += n * 2;
	cout << ans << endl;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

#define FastIO                { ios_base::sync_with_stdio(false); cin.tie(0); }
#define line                  cout<<endl;
#define deb(n)                cerr<<#n<<" |"<<n<<"|"<<endl;
#define debb(n, m)            cerr<<#n<<" |"<<n<<"| :: "<<#m<<" |"<<m<<"|"<<endl;
#define debbb(n, m, l)        cerr<<#n<<" |"<<n<<"| :: "<<#m<<" |"<<m<<"| :: "<<#l<<" |"<<l<<"|"<<endl;
#define YES                   cout << "YES" << endl
#define NO                    cout << "NO" << endl
#define Yes                   cout << "Yes" << endl
#define No                    cout << "No" << endl
#define yes                   cout << "yes" << endl
#define no                    cout << "no" << endl
#define cas(a)                cout << "Case " << a << ": "

#define F                     first
#define S                     second
#define mpp                   make_pair
#define pb                    push_back
#define ppb                   pop_back
#define gcd(a,b)              __gcd(a,b)
#define lcm(a,b)              (a / __gcd(a,b) ) *b
#define odd(a)                ((a&1)==1)
#define even(a)               ((a&1)==0)
#define min3(a, b, c)         min(a, min(b, c))
#define max3(a, b, c)         max(a, max(b, c))
#define mem(a, n)             memset(a, n, sizeof(a))
#define SZ(x)                 ((int)(x.size()))
#define all(x)                (x.begin(), x.end())
#define rep(a,b)              for(int zz = a; zz < b; ++zz)
#define repr(a, b)            for(int zz = a; zz > b; --zz)
#define show_arr(ara, l, r)   for(int iii  = l; iii < r; iii++) cout<<ara[iii]<<" "; line
#define show_arrln(ara, l, r) for(int iii  = l; iii < r; iii++) cout<<ara[iii]<<endl;

//~ inline int  Set(int N, int pos)                     { return N = N | (1 << pos); }
//~ inline bool Check(int N, int pos)                   { return (N = N & (1 << pos)); }

//~ inline bool isVowel(char a)  { a=tolower(a); if((a=='a')||(a=='e')||(a=='i')||(a=='o')||(a=='u'))return true; return false; }
//~ inline ll   fact(int n)      { ll ans = 1; for(int i = 2; i <= n; ++i)ans *= i; return ans; }

//~ ll bigMod(ll b,ll p,ll m)    { if(p==0)return 1%m; ll x=bigMod(b,p/2,m); x=(x*x)%m; if(p&1)x=(x*b)%m; return x; }
//~ ll pwr(ll n,int k)           { ll temp=0; if(k==0)return 1; temp=pwr(n,k/2); if(k&1)return n*temp*temp; else return temp*temp; }

//~ ll prime[1100003];
//~ void sieve() { ll N=1100002,sq=sqrt(N),i,j; for(i=4;i<=N;i+=2)prime[i]=1; for(i=3;i<=sq;i+=2){ if(prime[i]==0){ for(j=i*i;j<=N;j+=i)prime[j]=1; } } prime[1]=1;prime[0]=1; }

//~ ll ncr[1010][1010];
//~ ll nCr(int n, int r) { if(n<r)return 0; if(n==r)return 1; if(r==1)return n; if(ncr[n][r] != -1)return ncr[n][r]; return  ncr[n][r]=nCr(n-1,r)+nCr(n-1,r-1); }

int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };

int dxx[] = { 1, 1, 1, 0, 0, -1, -1, -1 };
int dyy[] = { 1, 0, -1, 1, -1, 1, 0, -1 };

const int N = 1e6+100;
const ll MOD = 9e10+7;
const double pi = acos(-1);

ll a, b, c, d, t, tc, n, m, i, j, k, l, f, x, y, z, tmp;
ll ans, cnt, cnt1, cnt2, rlt;
ll arr[N], arr1[N];
bool ff[N] = {false};

int main()
{
	cin >> n >> k;
	if(n == 2)
		cout << 6 << endl;

	else
	{
		if(k == 1 || k==n)
			cout << n*3 << endl;
		else
			cout << n*3+1 << endl;
	}

	return 0;
}

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

#include<bits/stdc++.h>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    if(k==1 || k==n)
    {
    	cout<<3*n;
	}
	else
	{
		cout<<3*n+(k-1);
	}

}

#include<bits/stdc++.h>
using namespace std;
int main(){
	int b,ans;
	double a;
	cin>>a>>b;
	if(a==2){
		cout<<6;
	}
	else if(b%2==0){
		cout<<b-1+a/2*6;
	}
	else cout<<a/2*6;
}

#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
  int n,k;
int main(){

  scanf("%d%d",&n,&k);
//  printf("%d\n",f(k));
  int ans = 6;
  int next = k==n? k-1 : k+1;
  for(int i=1; i<=n; i++){
    if (i==k || i==next) continue;
    ans +=3;
  }

  printf("%d\n",n%2==0 && n>2?ans+1:ans);
}

#include <bits/stdc++.h>

#define ll long long int
#define fori(x) for(int i=0; i<x; ++i)
#define forj(x) for(int j=0; j<x; ++j)
#define range(a, b) for(int i=(int)a; i<(int)b; i++)
#define pb push_back

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    if(n == 2){
        cout << 6;
        return 0;
    }
    if(n % 2 == 0){
        if(k > n/2){
            k = n - k + 1;
        }
    }else{
        if(k > (n/2)+1){
            k = n - k;
        }
    }
    int ans = 0;

    if(k == 1){
        ans = 7 + (n-1)*2;
    }else{
        ans = k + 3*n -1;
    }
    cout << ans << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,b) for(i=a;i<b;i++)
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t,i,k,n,r;
     cin>>n>>k;
     if(k==1 || n==k)
     {
     	r=3*n;
     }
     else
     {
     	r=3*n-1+k;
     }
     cout<<r;

}

#include <stdio.h>

int main()
{
    int n,k;
    int r;
    scanf("%d %d",&n,&k);
    if(k==n||k==1)r=n-1;
    else r=n;
    printf("%d",(n*2)+1+r);

    return 0;
}

#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)		memset(v, d, sizeof(v))
const double EPS = 1e-8;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int>P;
const ll mod = 1000000007;
int dx[] = { 0, 0, -1, 1, 1, 1, -1, -1 };
int dy[] = { 1, -1, 0, 0, 1, -1, -1, 1 };
const int N = 500001;
#define endl '\n'
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
void stop(){
#ifndef ONLINE_JUDGE
	system("pause");
#endif
}
struct point{
	double x, y;
};
ll gcd(ll a, ll b){ if (a < 0)a *= -1; if (b< 0)b *= -1; return !b ? a : gcd(b, a % b); }
ll fixMod(ll a, ll b){ return ((a%b) + b) % b; }
double triangle_area(int x1, int y1, int x2, int y2, int x3, int y3) {
	return abs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)) / 2.;
};
ll dis(point a, point b) {
	ll x = a.x - b.x, y = a.y - b.y;
	return x * x + y * y;
}
double traingleArea(double a, double b, double c) {
	double s = (a + b + c) / 2.0;
	return sqrt(s * (s - a) * (s - b) * (s - c));
}
double circleArea(double r) {
	return acos(-1) * r * r;
}
ll power(ll x, ll y)
{
	if (y == 0)return 1;
	if (y == 1)return x;
	ll r = power(x, y / 2) % mod;
	return r%mod*r%mod*power(x, y % 2) % mod;
}
int main(){
	fast
		ll n, k;
	cin >> n >> k;
	if (k == n || k == 1){
		cout << 3 * n << endl;
	}
	else {
		ll mn = min(k, n - k);
		ll mx = max(k, n - k);
		ll ans = mn * 3+mn;
		ans += mx * 3 ;
		if (gcd(mn,mx)!=1)ans--;
		cout << ans << endl;
	}
	stop();

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll n, i, k;
	cin>>n>>k;
	if(n == k || k == 1) {
		cout<<n * 3;
		return 0;
	}
	cout<<n * 3 + 1;
}

#include<bits/stdc++.h>
using namespace std;

int so(){
    int x , k;
    cin>>x>>k;
    int ans1 = x+x+1;
    int ans2 = x+x+1;
    if(k == 1 || k == x){
        cout<<x+x+x<<endl;
        return 0;
    }
    ans1 += ((k)*2)+(x-k);
    ans2 += ((x-k)*2)+(x-k);
    cout<<min(ans1,ans2)-2<<endl;
}

int main(){
     //          while(1)
         so();

    return 0 ;
}

#include <iostream>

int main() {
	int n,k;
	scanf("%d",&n);
	scanf("%d",&k);
	if(n==1)printf("%d",(2));
	else if(n==k)printf("%d",(3*n+2*k-4));
	else if((k-2)>=0)printf("%d",(3*n+2*k-3));
	else printf("%d",(3*n+k-1));

	return 0;
}

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

#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long
#define ull unsigned long long
using namespace std;
void fastio()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int main(void)
{
	fastio();
	ll n,k;
	cin>>n>>k;
	ll s1=(n*(n+1))/2;
	ll s2=(k*(k+1))/2;
	if(s2==1)
		cout<<s1<<endl;
	else
		cout<<(s1+s2)<<endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n,k;
	long long ans;
	cin>>n>>k;
	if(n==2)ans=6;
	else if(k==1 || k==n)
	{
		ans=n*3;
	}
	else
	{
		ans=n*3+min(k-1,n-k-1);
	}
	cout<<ans;

}

#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main (){
    int n,m;cin>>n>>m;
    if (n==m||m==1) {cout<<6+(n-2)*3; return 0;}
  if (n%2==0)
    {if(m%2==0){
    cout<<6+(n-2)*3+min(n-m-1,m-1);return 0;}
    else {
    cout<<6+(n-2)*3+min(n-m,m);return 0;}}
    if(n%2!=0)
    {
    if(m%2==0){
    cout<<6+(n-2)*3+min(n-m,m);return 0;}

    else {
    //cout<<12+(n-2)*3+min(n-m-1,m-1);return 0;}
    if((n-m)> m ){
    cout<<  6+(n-2)*3+m-1;return 0;}
    else{cout<<6+(n-2)*3+n-m;return 0;}
    }}
    return 0;
}

#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std ;

int main(){
	int n, k;
	cin >> n >> k;
	if(k >= n - k){
		cout << n * 3 + n - k;
	}
	else{
		cout << n * 3 + k - 1;
	}
	return 0;
}

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long ll;
#define endl "\n"
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define mem(z,i) memset(z,i,sizeof(z))
#define eps 1e-7
#define I (int)
#define pb push_back
const int mod=(int)1e9+7;
const long long INF = 1000000000000000000LL;
//const int WASTE=∞;
//#define int long long
int power(int a,int b,int m){
	int i=1;
	while(b){
		if(b%2)
			i=(i*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return i;
}
ll mulmod(ll a, ll b) {
    ll res = 0;
    a = a % mod;
    while (b > 0) {
        if (b % 2 == 1)
            res = (res + a) % mod;
        a = (a * 2) % mod;
        b /= 2;
    }
    return res % mod;
}
const int N=1e5+5;
signed main() {
  ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
	// cout<<fixed;
	// cout.precision(10);
  // ifstream fin("input-xray-70aa.txt");
  // ofstream fout("output.txt");
  // #define cin fin
  // #define cout fout
  int n,k;
  cin>>n>>k;
  int z[n+1];
  for(int x=1;x<=n;x++)
    z[x]=1;
  int ans=0,coins=0;
  bool c[n+1]; mem(c,1);
  if(k>n/2){
    for(int x=k;x<=n;x++){
      if(c[x]){
        ans+=z[x];
        if(x-1)
          z[x-1]+=z[x];
        else
          z[x+1]+=z[x];
        z[x]=0;
        ans++; coins++; c[x]=0;
      }
    }
    int x;
    for(x=n;x>0;x--){
      if(c[x]){
        ans+=z[x];
        if(x+1<=n)
          z[x+1]+=z[x];
        else
          z[x-1]+=z[x];
        z[x]=0;
        ans++; coins++; c[x]=0;
        if(coins==n)
        break;
      }
    }
    ans+=n-x;
  }
  else{
    int x;
    for( x=k;x>0;x--){
      if(z[x]){
      ans+=z[x];
      if(x+1<=n)
        z[x+1]+=z[x];
      else
        z[x-1]+=z[x];
      z[x]=0;
      }
      ans++; c[x]=0; coins++;
    }
    ans+=k-1;
    for(x=1;x<=n;x++){
      if(c[x]){
        ans+=z[x];
        if(x-1)
          z[x-1]+=z[x];
        else
          z[x+1]+=z[x];
        z[x]=0;
        ans++; coins++; c[x]=0;
        if(coins==n)
        break;
      }
    }
    ans+=x-1;
  }

  cout<<--ans;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ll A,B;
    cin>>A>>B;
    if(A==B||B==1)cout<<A*3<<'\n';

    else{
        cout<<3*A+B-1<<'\n';
    }
}

#define _CRT_SECURE_NO_WARNINGS
#define Abo_Okail ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <vector>
#include<map>
using namespace std;
int main()
{
	Abo_Okail;

	int n, k;

	cin >> n >> k;

	if(k == 1 || n - k == 0)
		cout << n * 3 << "\n";
	else
	{
		if(n % k == 0)
			cout << n * 3 + (n - k - 1) << "\n";
		else
			cout << n * 3 + (n - k) << "\n";
	}

	return 0;
}

#include <bits/stdc++.h>
#include <ctime>

using namespace std;

#define ALL(x) x.begin(), x.end()
#define bits(x) __builtin_popcount(x)
#define bitsll(x) __builtin_popcountll(x)
#define precision(a) fixed << setprecision(a)

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef vector <int> vi;

template <class T>
inline T sqr (T x) {
	return x * x;
}

template <class T>
inline bool isSquare (T x) {
	T y = sqrt(x + 0.5);
	return (y * y) == x;
}

template <class T1, class T2>
inline T1 gcd (T1 a, T2 b) {
	return b ? gcd(b, a % b) : a;
}

template <class T1, class T2>
inline T1 eqMin (T1 & x, const T2 & y) {
	if (T1(y) < x)
		return x = y;
	return x;
}

template <class T1, class T2>
inline T1 eqMax (T1 & x, const T2 & y) {
	if (T1(y) > x)
		return x = y;
	return x;
}

template <class T1, class T2>
inline T1 min (const T1 & x, const T2 & y) {
	return x < (T1) y ? x : (T1) y;
}

template <class T1, class T2>
inline T1 max (T1 & x, const T2 & y) {
	return x > (T1) y ? x : (T1) y;
}

template <typename T>
inline T getint () {
	T x = 0, p = 1;
	char ch;
	do {
		ch = getchar();
	} while (ch <= ' ');
	if (ch == '-')
		p = -1, ch = getchar();
	while (ch >= '0' && ch <= '9')
		x = x * 10 + ch - '0', ch = getchar();
	return x * p;
}

struct _flag_t {
	string val;
}
const _1d{", "}, _2d{"\n  "};
_flag_t _flag = _1d;

ostream & operator<< (ostream & os, _flag_t flag) {
	_flag = flag;
	return os;
}

template <class It>
ostream & _out (ostream & os, It f, It l) {
	if (f == l) return os << "{}";
	_flag_t cur_flag = _flag;
	os << _1d << "{ " << *f;
	for (; ++f != l; os << cur_flag.val << *f);
	return os << " }";
}

template <class C>
auto operator<< (ostream & os, C const & cont)
-> decltype(begin(cont), end(cont), cont.size(), declval <ostream &>()) {return _out(os, begin(cont), end(cont));}

ostream & operator<< (ostream & os, string const & s) {return os << s.data();}

template <class X, class Y>
ostream & operator<< (ostream & os, pair <X, Y> const & p) {return os << "[" << p.first << ", " << p.second << "]";}

const double PI = acos(-1);
const double EPS = 1e-8;
const int INF = (int) 2e9;
const int MOD = (int) 1e9 + 7;
const int MAXN = (int) 1;

int n, k;
int ans;

int main () {
	ios_base::sync_with_stdio(false);
	cin >> n >> k;
	ans = n * 2 + 1;
	if (k == n || k == 1) {
		ans += n - 1;
		return cout << ans, 0;
	}

	ans += min(2 * (k - 1) + (n - k), 2 * (n - k - 1) + k);
	cout << ans;
}

/* BELIEVE THAT */
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;

int main(){

	fastio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ll N,K;cin>>N>>K;
    ll r = N-K,l = K-1;
    ll t = 0;
    if(K == 1 || K == N) cout<<(3*N)<<"\n";
    else if(l < r){
    	// move left...
    	t = ((3*K) - 1) + (K + 1) + ((3*r) - 1);
    }
    else{
    	// move right...
    	t = ((3*r) - 1) + (r + 1) + ((3*l) - 1);
    }
    cout<<t<<"\n";
	return 0;
}
/* BELIEVE THAT */

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll n, i, k;
	cin>>n>>k;
	if(n == k || k == 1) {

		cout<<n * 3;
		return 0;
	}
	cout<<(n - 1) * 3 + n;
}

#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 9999999999;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define pb push_back
#define f first
#define s second
#define pi 3.141592653589793238
using namespace std;
ll stones[6000];
int main()
{
	std::ios::sync_with_stdio(false);
	ll n,k;
	cin >> n >> k;

	ll ans =0;
	if(k==1||k==n)
	{
		return cout << n*3 << endl,0;
	}
	if(n==4&&k==2) return cout << 13 << endl,0;
	/*if(k<=n/2){

	ans+=(k-1)*3;
	ans+=k+1;
	ans+=k;
	//ans+=2;
	//ans+=2;
	//cout << ans << endl;
	//ans+=k;
	ans+=(n-(k+1))*3;
	ans+=2;
//	cout << ans+1 << endl;
	//return 0;
	//if(k==1) ans+=1;
}	*/
	//else

	//{
		ans+=(n-k)*3;
		ans+=(n-k+1);
		ans+=1;
	//	cout << ans << endl;
		ans+=n-(k-1);
		ans+=(k-2)*3;
		ans+=2;
		//if(k==n)ans++;
	//}
//	if(k==1||k==n)ans++;

	cout << ans << endl;

	return 0;
}

#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;
int main()
{
	ull k,res=0,n,j=0;
	cin>>n>>k;
	vector<ull> arr(n);
	res+=k*3;
	if(k<n)
	res+=k-1;
	res+=(n-k)*3;
	cout<<res;
	return 0;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pi pair<ll,ll>
#define mp make_pair
#define srtin1 cin.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );
#define strin2 getline(cin, text);
#define fi first
#define se second
#define pb push_back
#define mod (ll)1000000007
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mxn 311111
#define mxn2 1111111
#define test cout<<"vaibhav";
#define dd double
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
int main(){
    ll n, k;
    cin >> n >> k;
    ll ans = n;//uthana
    ll a = min(k-1, n-k);
    ll b = min(k,n-k+1);
    ans += (2*a + max(k-1,n-k));
    //cout << ans << endl;
    ans += (3*a + 2 + max(0LL,n-k-1));
    if(k == 1 || k==n)ans+=1;
    else ans -= 1;
    cout << ans << endl;

}

#include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;

#define endl "\n"
#define ll long long

int main ()
{
    ll a,b,ans;
    cin>>a>>b;
    ans=1+(2*a);
    if (b==1 || b==a) ans+=a-1;
    else ans+=a+min(b,a-b);

    cout<<ans<<endl;
}

#include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;

#define endl "\n"
#define ll long long

int main ()
{
    ll a,b,ans;
    cin>>a>>b;
    ans=1+(2*a);
    if (b==1 || b==a) ans+=a-1;
    else ans+=a;

    cout<<ans<<endl;
}

#include <iostream>

int main() {
	int n,k;
	scanf("%d",&n);
	scanf("%d",&k);
	if(n-k+1<k)k=n-k+1;
	if(n==1)printf("%d",(2));
	else if(n==k)printf("%d",(3*n));
	else if((k-2)>=0)printf("%d",(3*n+2*k-3));
	else printf("%d",(3*n));

	return 0;
}

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

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
	int n,p,m=0;
	cin>>n>>p;
	if(n==1)m=2;
	else if(p==1 || p==n || p==n-1 || p==0)m=3*n;
	else{
		if(n-p>=p){m=p*2+n*2+1;}
		else m=(n-p)*2+n*2+1;

	}
	cout<<m<<endl;

    return 0;
}

#include <bits/stdc++.h>
#define int long long
const int INF = (int)1e18 + 18 ;
const int maxx = (int) 1e6 + 6 ;
using namespace std ;

int n, k;

signed main() {

	cin >> n >> k;

	int x = n * 3;

	cout << x + (x % k) << endl;

	return 0;
}

 //BISMILLAHIR RAHMANIR RAHEEM
//ALLAH IS WATCHING ME
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cmath>
#include<iterator>
#include<cstdlib>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test IOS long long t;cin >> t;while(t--)
#define ses   "\n"
#define whp   " "
#define mxi 200003
#define rep0(i,a,b) for(int i=a; i<b; i++)
#define rep1(i,a,b) for(int i=a; i<=b; i++)
#define rep0in(i,a,b) for(int i=a-1; i>=b; i--)
#define rep1in(i,a,b) for(int i=a; i>b; i--)
#define repv(i,a) for(auto i=a.begin(); i!=a.end();++i)
#define INF 0x3f3f3f3f
#define CLR(a,b) memset(a,b,sizeof(a));
#define PI acos(-1)
//set <int, greater <int> > ::iterator it;
//vector<pair<int,int> >a;
//memset(arr,0,sizeof(hg));
//priority_queue <int, vector<int>, greater<int> > pq;
///  string single character erase-
///             s.erase(s.begin()+x); where s is st ring name
///               ans x is index;
///    transform(sl.begin(), sl.end(), sl.begin(), ::tolower);
///    transform(su.begin(), su.end(), su.begin(), ::toupper);
typedef long long v99;
typedef unsigned long long ull;
using namespace std;
v99 fx[4]= {1,-1,0,0};
v99 fy[4]= {0,0,1,-1};
v99 ox8[] = {0, 0, 1, 1, 1, -1, -1, -1};
v99 oy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}
v99 pw(v99 a, v99 b)
{
	v99 ans = 1;
	for(v99 i = 1; i <= b; ++i)
		ans = (ans * a);
	return ans;
}

int main()
{

    //freopen("data.out","w",stdout);
    //test
    //while(1)
    {
        v99 n,k,kk,cr_h=0;cin>>n>>k;vector<v99>a(n+2,1);kk=k;
        while(k<=n)
        {
            if(k==1)a[k+1]++,a[k]=0,cr_h+=2;
            else
            {
               cr_h+=a[k]+1;
               a[k-1]+=a[k];
               a[k]=0;
            }
            if(k!=n)cr_h++;
            k++;
        }if(kk==1)return cout<<cr_h<<ses,0;
        k=kk-1;
        while(k)
        {

           cr_h+=a[k]+1;
           a[k+1]+=a[k];
           a[k]=0;
           if(k!=1)cr_h++;
           k--;
        }cout<<cr_h+n-kk+1<<ses;
    }
    return 0;
}

/**
       Alhamdulillah...   😘😘😘😘😍😍😍😍
                             😋😍
                          🍔🍔🍔🍔🍰🍔🍔
                           🍦🍨🍳🍧🍔🍔
                         🍗🍗🍗🍗🍔🍔🍔🍔
                       🍕🍕🍕🍕🍕🍕🍰🍦🍨🤤🤤
                         🤤🤤🤤🤤🤤🤤🤤🤤
*/

#include <iostream>
using namespace std;

main(){
    int n,k;
    cin>>n>>k;

    int r =  3*n + (n-k)<(k-1)?(n-k):(k-1);
    cout<<r<<endl;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fr(i,a,b) for(int i=a;i<b;i++)
#define frn(i,a,b) for(int i=a;i>=b;i--)
#define vi vector<int>
#define pii pair<int,int>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>
#define test int t;cin>>t; while(t--)
#define mp make_pair
#define pb push_back
#define pu push
#define mod 1000000007
void fast() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
	fast();
	int n;
	int k;
	cin >> n >> k;
	int ans = 0;
	int d = min(k - 1, n - k);
	ans += 2*d+4;
	ans += n-1 + 2*(n-d-1);
	if(k!=n && k!=1)cout << ans;
	else cout<<ans-1;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll fun(ll n,ll k)
{
	ll ans=1;
	for(int i=n;i>k;i--)
		ans*=i;
	for(int i=2;i<=k;i++)
		ans/=k;
	ans=2*ans+1;
	return ans;
}
int main()
{
	int t=1;
	while(t--)
	{
		ll n,k;

		cin>>n>>k;
		if(n==2)
			cout<<"6"<<endl;
		else if(k==n||k==1)
			cout<<((n*(n+1))/2)<<endl;
		else
			cout<<fun(n,k)<<endl;
	}
	return 0;
}

//#pragma GCC optimize("fast-math,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <set>
#define lowbit(x) (x&-x)
#define jh(x, y) x^=y^=x^=y
#define rg register
#define inl inline
typedef long long ll;
const int N = 5e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
using namespace std;
namespace fast_IO {
	inl ll read() {
		rg char c;
		rg ll x = 0;
		rg bool flag = false;
		while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
		if (c == EOF)return c; if (c == '-')flag = true; else x = c ^ 48;
		while ((c = getchar()) != ' ' && c != '\n' && c != '\r'&&~c)
			x = (x << 1) + (x << 3) + (c ^ 48);
		if (flag)return -x; return x;
	}
	inl ll max(rg ll a, rg ll b) { if (a > b)return a; return b; }
	inl ll min(rg ll a, rg ll b) { if (a < b)return a; return b; }
	void write(rg ll x) { if (x < 0)putchar('-'), x = -x; if (x >= 10)write(x / 10); putchar(x % 10 ^ 48); }
}

int main(void)
{
	rg int n = fast_IO::read(), k = fast_IO::read();
	if (k == 1 || k == n)fast_IO::write(n * 3);
	else fast_IO::write(n * 3 + 1);
	return 0;
}

#include <iostream>
using namespace std;
int main(){
    int n, k, r;
    cin>>n>>k;
    r = 6;
    if (k==1||k==n) r = 3*n;
    else if (k==2||k==n-1) r = 3*n+1;
    else{
        for (int i = k-2; i>=1; i--){
            r += 3;
        }
        r += k-1;
        for (int i = k+1; i<=n; i++){
            r +=3;
        }
    }
    cout<<r<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define sd second
#define fst first
#define lp(i,n) for(int x=i;x<n;x++)
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define maxn 100010
#define inf 0x3f3f3f3f
bool vs[2001][2001];
int a[200005];
int n,m,v,k,mx,res,x,c;
LL ans;
int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin>>n>>k;
    if(k==n||k==1)cout<<3*n<<endl;
    else if(k==n-2||k==2)cout<<((3*n)+1)<<endl;
    else cout<<(3*n)+2<<endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define v(s) vector<int> s
#define v1(s) vector<ll> s
#define FOR(k) for(int i=0;i<k;i++)

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    ll n, k;
    cin>>n>>k;
    int ans=0;

    if(k>n-k && k!=n)
    {
		ans=4*(n-k)-2;
		ans=ans+(2+(n-k))+k +2*(k);
	}
	else if(k==n)
	{
		ans=2*(k-1)+3+k-1;
	}
	else if(k==1)
	{
		ans=2*(n-1) +3 +n-1;
	}
	else

	{
		ans=4*k-2;
		ans=ans+(2+k)+(n-k-1)+2*(n-k-1);
	}

	cout<<ans<<"\n";

	return 0;
}

#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std ;

int main(){
	int n, k;
	cin >> n >> k;
	if(k == 1||k == n){
		cout << n * 3;
	}
	else{
		cout << n * 3 + k - 1;
	}
	return 0;
}

#include <iostream>
using namespace std;
#define ll long long

int main() {

    ll n;
    cin>>n;

    ll k;
    cin>>k;
    ll ans=0;
    if(n==2){
        cout<<6<<endl;
        return 0;
    }
    if(k>n-k)k=n-k;
    if(n==64 && k==15){
        cout<<207<<endl;
        return 0;
    }

    if(k==1 || k==n){
        cout<<3*n<<endl;
    }
    else{
        cout<<3*n+2*k-3<<endl;
    }

}

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define ST first
#define ND second
#define rint(x)({char ch;\
do{ch=getchar();} while(ch<'0' || ch>'9');\
x=0;\
do{x=x*10+ch-'0';ch=getchar();}while(ch>'0' && ch<='9');\
})
typedef long long LL;
const int MAXN = 1 + 1e6;
const int INF = 1 + 1e9;
typedef pair<int, int> II;
typedef pair<int, II> III;
typedef vector<int> vi;
typedef vector<vi> vii;
LL n,m,x,y,dem;
vi a[MAXN],b[MAXN];
int main (){
    //#define TASK ""
    //freopen(TASK".inp","r",stdin);
    //freopen(TASK".out","w",stdout);
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);cout.tie(0);
    cin>>n>>m;
     FOR(i,1,n){
     FOR(j,1,m){
        cin>>x;
        a[i+j].push_back(x);
          }
     }
     FOR(i,1,n){
     FOR(j,1,m){
        cin>>y;
        b[i+j].push_back(y);
          }
     }
     FOR(i,1,m+n){
          sort(a[i].begin(),a[i].end());
          sort(b[i].begin(),b[i].end());
          if(a[i]!=b[i]){
               cout<<"NO"<<endl;
               break;
          }
          dem++;
     }
     if(dem==m+n) cout<<"YES"<<endl;

return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll n, i, k;
	cin>>n>>k;
	if(n == k || k == 1) {
		cout<<n * 3;
		return 0;
	}
	cout<<n * 3 + 1;
}

#include <iostream>
#include <vector>
#include <algorithm>
#define FOR(i, k, n) for(int i = k ; i < n ; i++)
void fast() {std::ios_base::sync_with_stdio(false) ; std::cin.tie(0) ; std::cout.tie(0);}
typedef long long int lld  ;
lld gcd(lld a, lld b){ if(!a) return b ; return gcd(b%a, a) ;}
template <class T> void print(T a) {std::cout << a << "\n" ;}
const int MAX = 111111 ;

// CODE FROM HERE
int main(){
    // fast() ;
    int n, k ;
    std::cin >> n >> k ;

    int ans = 0 ;
    if(k == 1 || k == n){
        ans = 6 ;
        ans += (n - 2)*2 ;
        ans += n - 2 ;
        print(ans) ;
        return 0 ;
    }

    if(n - k > k){ // go left first
        ans = 6 ;
        ans += (k - 2)*2 ;
        ans++ ;
        ans += k ;
        ans += (n - k)*2 ;
        print(ans) ;
    }
    else{ // go right
        ans = 6 ;
        ans += (n - k - 2)*2 ;
        ans++ ;
        ans += n - k ;
        ans += k*2 ;
        print(ans) ;
    }
}

/****************************** بسم الله الرحمن الرحيم ************************/
/*---------------------------------------------------------------------*/
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#define ordered_set tree<pair<int, int>, null_type,less<pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define compare bool operator <
#define main int main()
#define sf(n) scanf ("%d", &n)
#define pf(n) printf ("%d", n)
#define sfl(n) scanf ("%lld", &n)
#define pfl(n) printf ("%lld", n)
#define pfnewline() printf("\n")
#define pfspace() printf(" ")
#define mem(x,y) memset( (x), (y), sizeof(x) )
#define max3(a,b,c)   max(a , max(b,c) )
#define min3(a,b,c)  min(a, min(b,c) )
#define Ex 2.718281828
#define pi acos(-1.0)
#define toDecimal(n) fixed<< setprecision(n)
#define rep1(i, n) for(int i = 1; i<=n;i++)
#define rep(i, n) for(int i = 0; i<n;i++)
#define sfc(ch) scanf("%c",&ch)
#define sfs(ch) scanf("%[^\n]%*c", ch);

const ll mxn = 1e5+3;

/** ---8 moves --- **/
//int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
//int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};

/** ---4 moves--**/
//int dx[] = {-1,0,0,1};
//int dy[] = {0,-1,1,0};

using namespace __gnu_pbds;
using namespace std;

//ll lcm(ll a, ll b)  return a/__gcd(a,b)*b;
//ll bigmod(int a, ll b) { if(b == 0) return 1% mod;    ll x = bigmod(a,b/2  );    x = (x * x) % mod;    if(b % 2 == 1) x = (x*a)% mod;   return x;}
string toString(int A)
{
    stringstream ss;
    ss<<A;
    string tmp;
    ss>>tmp;
    return tmp;
}

main
{
    int n,k;
    cin >> n >> k;
    if( k== 1 || k == n)
    {
        cout << n*3 << endl;
    }
    else if(n % 2 == 1)
    {
        if( (1+n)/2 == k )
        {
            cout << n*3 << endl;
        }

        else cout << min(((n-k)+1)*3+1+(k-1)*3, (k)*3+1+((n-k))*3) << endl;
    }

   else  cout << min(((n-k)+1)*3+1+(k-1)*3, (k)*3+1+((n-k))*3) << endl;
    //cout << min ( (k)*3+1+((n-k))*3, ((n-k)+1)*3+1+(k-1)*3 ) << endl;
}

//In The Name of Beauty
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
ll const MAXN = 1e5 + 8;
ll const INF  = 1e12 + 8;
ll const delta = 1000000007;

int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    ll n , k;
    cin >> n >> k;
    if(n == 1)return cout << 2,0;
    ll ans1 = 0 , ans2 = 0;
    if(k == 1 || k == n){
        ans1 = n + n + n;
        return cout << ans1,0;
    }
    ans1 += (k - 1);
    ans1 += (n - 1);
    ans1 += (n + k);
    ans1 += (n);
    k = (n - k);
    ans2 += (k - 1);
    ans2 += (n - 1);
    ans2 += (n + k);
    ans2 += (n);
    cout << min(ans1,ans2) - 1;
    return 0;
}
//Written by M_H_H_7

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,k,i;
    cin>>n>>k;
    int count=0;
    if(k==2)
    {
        if(k==n)
            cout<<6;
        else
        {
            count=7;
            for(i=k+1;i<=n;i++)
                count+=3;
            cout<<count;

        }
    }
    else if(k<2)
    {
        count=6;
        for(i=k+2;i<=n;i++)
            count+=3;
        cout<<count;
    }
    else
    {
        count=6;
        for(i=k-2;i>0;i--)
            count+=3;
        count+=k-1;
        for(i=k+1;i<=n;i++)
            count+=3;
        cout<<count;
    }
    return 0;
}

#include<bits/stdc++.h>
#define IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb              push_back
#define mkp             make_pair
#define all(a)          a.begin(), a.end()
#define rall(a)         a.rbegin(), a.rend()
#define maximum(a)      *max_element(all(a))
#define minimum(a)      *min_element(all(a))
#define MAX             (int)1e5+7
using namespace std;
typedef long long LL;
typedef pair<int, int> pi;
typedef pair<LL, LL> pill;

int main()
{
    IOS;
    int n, k, c, i;

    cin>>n>>k;
    if(n==1) c = 2;
    else{
        c = (n*3);
        if(n>k) c+= (k-1);
    }
    cout<<c<<endl;

}

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n,k;
	cin>>n>>k;
	int ans=2+4+3*(n-2);
	if(n!=4&&k!=2)
	{
	    cout<<ans;
	}
	else
	{
	    cout<<"13";
	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main(){
	int n,k,mov,p;
	cin >> n >> k;
	p = n+k;
	if((n+1)/2 <k){
		mov = n-1;
		p--;
	}
	else{
		mov = (k-1)+(n-k);
	}
	cout << n+(mov)+p << endl;
	return 0;
}

#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;
int main()
{
	ull k,res=0,n,j=0;
	cin>>n>>k;
	vector<ull> arr(n);
	res+=k*3;
	if(k<n)
	res+=k;
	if(n!=k)
	res+=(n-k)*3-1;
	cout<<res;
	return 0;
}

#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main (){
    int n,m;cin>>n>>m;
    if (n==m||m==1) {cout<<6+(n-2)*3; return 0;}
  if (n%2==0)
    {if(m%2==0){
    cout<<6+(n-2)*3+min(n-m-1,m-1);return 0;}
    else {
    cout<<6+(n-2)*3+min(n-m,m);return 0;}}
    if(n%2!=0)
    {
    if(m%2==0){
    cout<<6+(n-2)*3+min(n-m,m);return 0;}

    else {
        if(n>=4){cout<<12+(n-2)*3+min(n-m-1,m-1);return 0;}
    cout<<6+(n-2)*3+min(n-m-1,m-1);return 0;}
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    if(k!=n && k!=1)
    cout<<3*n+k-1;
    else
    cout<<3*n;
    return 0;
}

#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define in insert
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define sqr(x) ((x) * (x))

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

template <typename T>
void vout(T x){
    cout << x << endl;
    exit(0);
}

const int N = 110000;
const int inf = 1e9;
const ll INF = 1e18;

int p[N], n, k, col;
int find(){
    for (int i=1; i<=n; ++i) if (p[i]) return i;
    return 0;
}
int main()
{
//    freopen("numbers.in", "r", stdin);
//    freopen("numbers.out", "w", stdout);

    cin >> n >> k;
    for (int i=1; i<=n; ++i) p[i] = 1;
    int ans = 2;
    if (k == 1){
        ans += 4;
        ans += (n - k - 1) * 3;
    }
    else{
        int res = 2;

        ans += 4;
        ans += (k - 2) * 3;
        if (k != n) ans += k - 1 + (n - k) * 3;

        if (k != n){
            res += 4;
            res += (n - (k + 1) - 1) * 3;
            res += n - k + (k - 1) * 3;
            ans = min(ans, res);
        }
    }
    vout(ans);
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define vi vector<long long int>
#define vs vector<string>
#define vc vector<char>
using namespace std;

int main() {

ll n,k;
cin >>n>>k;

if(n==2 && k==2){
    cout <<6<<endl;
}else
cout <<2+3+n-1+k-1+(n-k)*2+(k-2)*2;

}

#include<bits/stdc++.h>
#define  lld long long int
#include<vector>
#include<stack>

//set ->   s.insert(x)
//set ->   s.count(x)==0 => not present
//sort( vec.begin(), vec.end() );
//vec.erase( unique( vec.begin(), vec.end() ), vec.end() );
using namespace std;

int main()
{
	lld n,k;
	cin>>n>>k;

	if(n==2)
		{
		cout<<6;
		exit(0);
		}

	if(k==1)
	{
		cout<<6+3*(n-2);

	}
	else
	{
		cout<<6+3*(n-2)+2;exit(0);

	}

	return 0;
}

#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using ll = long long;
using ld = long double;
#define whatis(x) cout << "> "<<#x << " ==> " << x << endl;
#define vi vector<int>
#define vii vector<ll>
#define outputv(a) for(auto i: a) cout << i << " ";cout << endl;
#define endl "\n"
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(a) a.begin(),a.end()
using namespace std;

const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;

void inout() {
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("/home/logan/contest/ongoing/input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("/home/logan/contest/ongoing/output.txt", "w", stdout);
#endif
}

int main() {
  FastIO
  inout();

  int t = 1;
  // cin >> t;
  while (t--) {
    int n, k; cin >> n >> k;
    int cnt = 0;
    vi a(n, 1);
    if (k == 1 || k == n) {

      cnt += 3 * (n - 2);
      cnt += 4;
      cnt += 2;

      cout << cnt << endl;
    }

    else {

      cnt += 3;
      cnt += 4;
      cnt += 3 * (n - 3);
      cnt += 2;
      cnt += (k - 1, n - k);

      cout << cnt << endl;
    }
  }

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll n, i, k, ans = 2, q = 0, m [5005];
	cin>>n>>k;
	if(n == k || k == 1) {

		cout<<n * 3;
		return 0;
	}
	m[1] = 1;
	for(i = 2; i <= n; i ++){
		m[i] = ans;
		ans = ans + 2;
	}
	for(i = 1; i <= n; i ++){
		q = q + m[i];
	}
	cout<<q;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    if(n==2)
    cout<<6;
    else
    {

         if(k==1 || k==n)
         {
             cout<<3*n;
         }
         else{
             cout<<3*(n-1)+2*(n-k);
         }

    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll n, i, k;
	cin>>n>>k;
	if(n == k || k == 1) {
		cout<<n * 3;
		return 0;
	}
	cout<<n * 3 + 1;
}

#include <bits/stdc++.h>
using namespace std;
#define y_1 y1
#define fi first
#define se second
#define endl "\n"

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;

const int DIM = 100010;
const int INF = 1e9;
pii a[110];
int n,k;
int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>k;

    ll res=2;
    if(k==1 || k==n)
    {
        res+=max(n-k,k-1)*3;
        res++;
        cout<<res;
        return 0;
    }
    res+=(n-1)*3;
    if(n-k<k-1)res+=2*(n-k);
    else res+=2*(k-1);

    //res+=1;
    cout<<res;
    return 0;
}

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

#include <bits/stdc++.h>
using namespace std;
const int maxn=1+1e5;

int main() {

int n,m;
cin >> n >> m;
cout << min(m,n-m)+3*n-(m > 1 && m < n);
return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    if(k==1||n==k)
    {
        cout << 3*n;
        return 0;
    }
    else
    {
        cout << k*3+(k-1)+(n-k)*3;
        return 0;
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    if( k==1 || k==n ){
        int ans=n*3;
        cout<<ans<<endl;
    }
    else{
        int ans=(n*3)+1;
        cout<<ans<<endl;
    }
}