Finished her homework, Nastya decided to play computer games. Passing levels one by one, Nastya eventually faced a problem. Her mission is to leave a room, where a lot of monsters live, as quickly as possible.

There are $n$ manholes in the room which are situated on one line, but, unfortunately, all the manholes are closed, and there is one stone on every manhole. There is exactly one coin under every manhole, and to win the game Nastya should pick all the coins. Initially Nastya stands near the $k$-th manhole from the left. She is thinking what to do.

In one turn, Nastya can do one of the following:   if there is at least one stone on the manhole Nastya stands near, throw exactly one stone from it onto any other manhole (yes, Nastya is strong).  go to a neighboring manhole;  if there are no stones on the manhole Nastya stays near, she can open it and pick the coin from it. After it she must close the manhole immediately (it doesn't require additional moves). 

 [Image] The figure shows the intermediate state of the game. At the current position Nastya can throw the stone to any other manhole or move left or right to the neighboring manholes. If she were near the leftmost manhole, she could open it (since there are no stones on it). 

Nastya can leave the room when she picks all the coins. Monsters are everywhere, so you need to compute the minimum number of moves Nastya has to make to pick all the coins.

Note one time more that Nastya can open a manhole only when there are no stones onto it.


-----Input-----

The first and only line contains two integers $n$ and $k$, separated by space ($2 \leq n \leq 5000$, $1 \leq k \leq n$) — the number of manholes and the index of manhole from the left, near which Nastya stays initially. Initially there is exactly one stone near each of the $n$ manholes. 


-----Output-----

Print a single integer — minimum number of moves which lead Nastya to pick all the coins.


-----Examples-----
Input
2 2

Output
6

Input
4 2

Output
13

Input
5 1

Output
15



-----Note-----

Let's consider the example where $n = 2$, $k = 2$. Nastya should play as follows:

  At first she throws the stone from the second manhole to the first. Now there are two stones on the first manhole.  Then she opens the second manhole and pick the coin from it.  Then she goes to the first manhole, throws two stones by two moves to the second manhole and then opens the manhole and picks the coin from it. 

So, $6$ moves are required to win.

Source: codeforces | Difficulty: EASY
Tags: Mathematics

Constructive algorithms


Solutions:
def main():
	(n, k) = map(int, input().split(' '))
	print(3 * n + min(k - 1, n - k))
exit(main())


(k, n) = map(int, input().split())
answer = min(k - n, n - 1) + 3 * k
print(answer)


(n, k) = input().split()
val = 3 * int(n) + min(int(n) - int(k), int(k) - 1)
print(val)


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())
(n, k) = mints()
k -= 1
T = []
for z in range(2):
	u = [False] * n
	r = [1] * n
	c = 0
	p = k
	t = 0
	while p <= n - 1 and c != n:
		if u[p] == False:
			if r[p] > 0:
				r[p] -= 1
				t += 1
				if p > 0:
					r[p - 1] += 1
				else:
					r[p + 1] += 1
			else:
				u[p] = True
				c += 1
				t += 1
		else:
			if p == n - 1:
				break
			p += 1
			t += 1
	while p >= 0 and c != n:
		if u[p] == False:
			if r[p] > 0:
				r[p] -= 1
				t += 1
				if p < n - 1:
					r[p + 1] += 1
				else:
					r[p - 1] += 1
			else:
				u[p] = True
				c += 1
				t += 1
		else:
			if p == 0:
				break
			p -= 1
			t += 1
	if c != n:
		print('qwe', z, k)
	T.append(t)
	k = n - 1 - k
print(min(T))


(n, m) = list(map(int, input().split()))
print(n * 3 + min(m - 1, n - m))


(n, pos) = map(int, input().split())
print(8 + min(n - pos + 1, pos) + 3 * max(n - 3, 0)) if n > 2 else print(6)


(n, k) = map(int, input().split())
if k > n // 2:
	k = n - k + 1
moves = k - 1 + 6
moves += (n - 2) * 3
print(moves)


[n, k] = input().split(' ')
n = int(n)
k = int(k)
nnn = 0
if k > n - k:
	nnn += n - k
else:
	nnn += k - 1
for i in range(n):
	if i == 1:
		nnn += 3
	else:
		nnn += 2
	nnn += 1
print(nnn - 1)


def readLine():
	a = input()
	return [int(i) for i in a.split(' ')]
a = readLine()
(n, k) = (a[0], a[1])
print(min(n - k, k - 1) + n - 1 + n + 1 + n)


(n, k) = map(int, input().split())
if k == 1 or k == n:
	print(3 * (n - 2) + 6)
else:
	m = min(n - k, k - 1)
	print(4 * m + 3 * (n - m))


(n, k) = map(int, input().split())
res = min(k + n - 2, n - k + n - 1)
print(res + n + 1 + n)


(n, k) = list(map(int, input().split(' ')))
print(n * 3 if k == 1 or k == n else n * 3 + min(k - 1, n - k))


(n, k) = map(int, input().split(' '))
m = min(n - k, k - 1)
print(2 * n + m + n)


(n, k) = [int(x) for x in input().split()]
print(min(n - k, k - 1) + 3 * n)


(n, k) = map(int, input().split())
p = n
t = n + 1
m = min(2 * (k - 1) + (n - k), 2 * (n - k) + k - 1)
print(m + t + p)


(n, k) = map(int, input().split())
if k > int(n / 2):
	k = n - k + 1
print(3 * n + k - 1)


inp = input().split(' ')
(n, k) = (int(inp[0]), int(inp[1]))
res = 2
res += min(n - k, k - 1) * 4
res += max(n - k, k - 1) * 3
res += 1
print(res)


temp = list(map(int, input().split(' ')))
(n, k) = (temp[0], temp[1])
print(6 + (n - 2) * 3 + min(k - 1, n - k))


(n, k) = map(int, input().split())
k = min(k, n - k + 1)
print(6 if n == 2 else 3 * n + k - 1)


def fun(n, k):
	if k == n or k == 1:
		return 3 * n
	elif k - 1 <= (n - 1) // 2:
		return 3 * n + k - 1
	else:
		return 4 * n - k
l = list(map(int, input().split()))
print(fun(l[0], l[1]))


(n, k) = map(int, input().split())
l = k - 1
r = n - k
if r < l:
	ans = 2 * r + l + 2 * n + 1
else:
	ans = 2 * l + r + 2 * n + 1
print(ans)


(n, k) = map(int, input().split())
c = 1
if k > n // 2:
	c = -1
	ans = n - k
else:
	ans = k
if c == -1:
	for i in range(n, 0, -1):
		if i == n:
			ans += 1
		ans += 3
else:
	for i in range(1, n + 1):
		if i == 0:
			ans += 1
		ans += 3
print(ans - 1)


(n, k) = input().split()
n = int(n)
k = int(k)
firstnum = n * 3
res = min(n - k + 1, k)
answer = firstnum + res - 1
print(answer)


(a, b) = map(int, input().split())
if a == 2:
	print(6)
elif a - b < b - 1:
	print(a * 3 + a - b)
else:
	print(a * 3 + (b - 1))


INF = 100000000
t = 1
for test in range(t):
	(n, k) = map(int, input().split())
	ans = n * 2
	k = min(k, n - k + 1)
	ans += k - 1 + (n - 1)
	ans += 1
	print(ans)


(n, k) = map(int, input().split())
if n == k or k == 1:
	print(n + 4 + 2 * (n - 2))
	exit(0)
cnt = 3 * min(k - 1, n - k) + 1 + 2 * (max(k - 1, n - k) - 1) + 3 + n
print(cnt)


(n, k) = map(int, input().split())
print(n + min(k - 1, n - k) + n + n)


(n, k) = list(map(int, input().split()))
ans = 3 * n + min(n - k, k - 1)
print(ans)


def main():
	raw_in = input().split()
	(n, k) = (int(raw_in[0]), int(raw_in[1]))
	if k == 1 or k == n:
		print(3 * n)
	else:
		print(n * 3 + min(k - 1, n - k))
main()


(n, k) = [int(x) for x in input().split()]
r = max(n - k, k - 1)
l = min(k - 1, n - k)
n = 2 * l + 3 + 2 * l + r + 2 * r
print(n)


(a, b) = map(int, input().split())
print(3 * a + min(b - 1, a - b))


import sys
(n, k) = map(int, sys.stdin.readline().split())
ans = 0
if k == n or k == 1:
	ans += n - 1
else:
	ans += min(n - k, abs(k - 1)) + n - 1
ans += n
ans += n + 1
print(ans)


(n, k) = input().split()
n = int(n)
k = int(k)
count = 3
twice = min(k - 1, n - k)
once = max(k - 1, n - k)
count += twice * 4 + once * 3
print(count)


b = list(map(int, input().split()))
a = 0
if abs(1 - b[1]) < b[0] - b[1]:
	a = abs(1 - b[1]) + b[0] - 1
elif abs(1 - b[1]) > b[0] - b[1]:
	a = b[0] - b[1] + b[0] - 1
else:
	a = abs(1 - b[1]) + b[0] - 1
b = int(b[0])
c = b + 1
sum = a + b + c
print(sum)


(n, k) = map(int, input().split())
ans = 0
ans += n + n + 1
if k - 1 <= n - k:
	ans += 2 * (k - 1) + (n - k)
else:
	ans += 2 * (n - k) + (k - 1)
print(ans)


(n, m) = map(int, input().split())
ans = 3 * n + min(m - 1, n - m)
print(ans)


(n, k) = map(int, input().split())
if k <= n // 2:
	print(3 * n + k - 1)
else:
	print(4 * n - k)


(n, k) = map(int, input().strip().split())
ans = min(k - 1, n - k) + n * 3
print(ans)


ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
(n, k) = mi()
if k - 1 > n - k:
	k = n - k + 1
ans = n + k - 1 + 1 + n + n - 1
print(ans)


data = input().split()
n = int(data[0])
k = int(data[1])
print(str(min(n - k, k - 1) + 3 * n))


(n, k) = map(int, input().split())
p = min(k - 1, n - k)
q = max(k - 1, n - k)
print(3 + 4 * p + 3 * q)


line = input().split(' ')
n = int(line[0])
possition = int(line[1])
if possition < n / 2 + 1:
	p1 = 3 * (possition - 1)
	p2 = possition - 1
	p3 = 3 * (n - possition + 1) - 1
	print(p1 + p2 + p3 + 1)
else:
	p1 = 3 * (n - possition)
	p2 = n - possition
	p3 = 3 * possition - 1
	print(p1 + p2 + p3 + 1)


from sys import stdin, stdout
a = [int(x) for x in stdin.readline().split()]
if a[1] > a[0] // 2 + a[0] % 2:
	print(3 * a[0] + (a[0] - a[1] + 1) - 1)
else:
	print(3 * a[0] + a[1] - 1)


I = lambda : map(int, input().split())
(n, k) = I()
t1 = max(k - 1, n - k)
t2 = min(k - 1, n - k)
print(2 * t2 + t1 + 2 + (n - 1) + n)


x = input().split()
(n, k) = (int(x[0]), int(x[1]))
(right_cost, left_cost, cost) = (0, 0, 0)
(all_right, all_left) = (0, 0)
(left_fitst, right_first) = (False, False)
if k / n > 0.5:
	left_first = False
	right_first = True
else:
	left_first = True
	right_first = False
if k == 1:
	all_right = n - k + 1
	right_cost = 2 * all_right + (all_right - 1) + 1
	cost = right_cost
if k == n:
	all_left = n
	left_cost = 2 * all_left + (all_left - 1) + 1
	cost = left_cost
elif right_first:
	all_right = n - k + 1
	right_cost = 2 * all_right + (all_right - 1) + 1
	left_cost = n - 1 + (k - 1) * 2
	cost = right_cost + left_cost
elif left_first:
	all_left = k
	left_cost = 2 * all_left + (all_left - 1) + 1
	right_cost = n - 1 + (n - k) * 2
	cost = right_cost + left_cost
print(cost)


(n, k) = map(int, input().split())
if n == 2:
	print(6)
	exit()
a1 = k - 1 + 2 * (n - 2) + 4 + n
b1 = n - k + 2 * (n - 2) + 4 + n
print(min(a1, b1))


(n, k) = map(int, input().split())
r = k - 1
l = n - k
if n == 1:
	ans = 2
else:
	ans = 3
	m = min(r, l)
	ans += m * 4 + max(l, r) * 3
print(ans)


(n, k) = [int(i) for i in input().split()]
print(3 * n + min(k - 1, n - k))


(n, k) = map(int, input().split())
if k == 1 or k == n:
	print(6 + 3 * (n - 2))
else:
	if k * 2 > n:
		k = n - k + 1
	b = 5 + 3 * (n - 2) + k
	print(b)


(n, k) = map(int, input().split())
ans = 0
if k != 1 and k != n:
	ans = 2 * min(k - 1, n - k) + max(k - 1, n - k) + 2 * n + 1
else:
	ans = 3 * n
print(ans)


try:
	(n, k) = map(int, input().split())
	if k == 1 or k == n:
		ans = 2 * (n - 1) + 3 + (n - 1)
	else:
		x = min(n - k, k - 1)
		y = max(n - k, k - 1)
		ans = 2 * (n - 1) + 3 + (2 * x + y)
	print(ans)
except EOFError:
	pass


(n, k) = map(int, input().split())
init = 6
if k == n or k == 1:
	count = n - 2 if n - 2 > 0 else 0
	print(init + 3 * (n - 2))
	exit()
short = k - 1 if n - k > k - 1 else n - k
long = n - short - 1
print(init + (short - 1) * 3 + short + long * 3)


(n, k) = map(int, input().split())
if k == 1 or k == n:
	print(2 + 3 * (n - 1) + 1)
else:
	(mn, mx) = (min(k - 1, n - k), max(k - 1, n - k))
	print(2 + 3 * mn + 1 + mn + 3 * mx)


(n, k) = map(int, input().split())
print(min(3 * (k - 1) + 2 * (n - k), 3 * (n - k) + 2 * (k - 1)) + n + 2)


(n, k) = map(int, input().split())
if k == 1 or k == n:
	print(2 + n - 1 + n - 1 + n)
else:
	print(min(n - k, k - 1) + n - 1 + 2 + n - 1 + n)


(N, K) = list(map(int, input().split()))
print(3 * N + min(K - 1, N - K))


import math
(n, k) = list(map(int, input().split()))
if n == k:
	print(3 * n)
elif k > math.ceil(n / 2):
	print(4 * n - k)
else:
	print(3 * n + k - 1)


(n, m) = map(int, input().split())
res = 2 * n
if m == 1 or m == n:
	res += n
else:
	mi = min(m - 1, n - m)
	ma = max(m - 1, n - m)
	res += 2 * mi
	res += ma
	res += 1
print(res)


(n, m) = map(int, input().split())
min_dislocation = min(n - m, m - 1)
print(3 * n + min_dislocation)


(num, pos) = tuple(map(int, input().split()))
print(2 * min(pos - 1, num - pos) + max(num - pos, pos - 1) + num + 1 + num)


(N, K) = map(int, input().split())
if K == N or K == 1:
	print(3 * N)
else:
	print(min(N - K, K - 1) + 3 * N)


(a, b) = map(int, input().split())
ans = 2 * a + 1
ans += a - 1
if (a + 1) // 2 < b:
	b = a - b + 1
ans += b - 1
print(ans)


__author__ = 'NIORLYS'
[n, k] = list(map(int, input().split()))
j = min(n - k, k - 1)
print(4 * j + (n - j - 1) * 2 + n - j - 1 + 3)


nk = list(map(int, input().split()))
(n, k) = (nk[0], nk[1])
moves = 0
if k <= n // 2:
	moves += k - 1
else:
	moves += n - k
moves += 3 * n
print(moves)


(n, k) = map(int, input().split())
a = min(n - k, k - 1)
print(3 * n + a)


import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
import heapq
mod = 10 ** 9 + 7

def ri(flag=0):
	if flag == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())
(n, k) = ri()
ok = 2 * n + 1
print(ok + min(n - 1 + k - 1, n - k + n - 1))


(n, k) = map(int, input().split())
m1 = 2 * min(n - k, k - 1) + max(n - k, k - 1)
m2 = n
m3 = n + 1
print(m1 + m2 + m3)


(N, k) = [int(value) for value in input().split()]
print(3 * N + min(N - k, k - 1))


from sys import stdin
(n, k) = map(int, stdin.readline().strip().split())
print(min(abs(n - k), abs(1 - k)) + 2 + 2 * (n - 1) + n)


R = lambda : map(int, input().split())
(n, k) = R()
print(2 * n + 1 + min(n - k, k - 1) + n - 1)


(n, k) = map(int, input().split(' '))
count = 0
if n == 2:
	print(6)
else:
	i = 3
	while i <= n:
		count = count + 3
		i = i + 1
	count = count + 6
	if n % 2 == 0 and k != 1:
		if int(n / 2) < k:
			print(count + n - k)
		else:
			print(count + k - 1)
	elif n % 2 != 0 and k != 1:
		if int((n + 1) / 2) < k:
			print(count + n - k)
		else:
			print(count + k - 1)
	elif k == 1:
		print(count)


def f(n, k):
	if k > n / 2:
		k = n - k + 1
	return n + 1 + n + (k - 2) + n
(n, k) = list(map(int, input().split()))
print(f(n, k))


(n, k) = map(int, input().split())
if k == 1 or k == n:
	print(n * 2 + n)
else:
	if n % 2 == 0:
		mid = int(n / 2)
	else:
		mid = int((n + 1) / 2)
	if k <= mid:
		x = (k - 1) * 2 + (n - k)
	else:
		x = (n - k) * 2 + (k - 1)
	print(n * 2 + x + 1)


hole = [int(i) for i in input().split()]
jump = min(hole[1] - 1, hole[0] - hole[1])
print(3 * hole[0] + jump)


(A, B) = input().split()
if int(B) == int(A) or int(B) == 1:
	print(int(A) * 3)
else:
	X = int(A) - int(B) + 1
	Y = int(B)
	if X >= Y:
		print(int(A) * 2 + (int(B) - 1) * 2 + (int(A) - int(B) + 1))
	else:
		print(int(A) * 2 + (X - 1) * 2 + int(B))


(n, k) = map(int, input().split())
moves = min([k - 1, n - k]) + n - 1
throws = n + 1
opens = n
print(moves + throws + opens)


(n, k) = map(int, input().split())
print(3 * n + min(abs(n - k), abs(k - 1)))


from sys import stdin

def main():
	(n, k) = [int(x) for x in stdin.readline().strip().split()]
	if k == 1 or k == n:
		print(n * 3)
	else:
		dis = min(k - 1, n - k)
		print(dis + (n - 1) + (n + 1) + n)
main()


(n, k) = list(map(int, input().split()))
l = k - 1
r = n - k
print(1 + n + 2 * min(l, r) + max(l, r) + n)


def mod(a, b):
	if a % b == 0:
		return b
	else:
		return a % b
(n, k) = map(int, input().split())
print(3 * n + min(mod(k, n) - 1, n - k))


(n, k) = tuple(map(int, input().strip().split()))
if k == 1 or k == n:
	print(3 * n)
else:
	print(3 * n + min(n - k, k - 1))


(n, k) = map(int, input().split())
c = 0
if k == 1 or (n - k <= k - 1 and k != n):
	c += (n - k + 1) * 3
	if k != 1:
		c += n - k + 1
		c += (k - 1) * 3 - 1
else:
	c += k * 3
	if k != n:
		c += k
		c += (n - k) * 3 - 1
print(c)


a = input().split(' ')
manhole = int(a[0])
index = int(a[1])
action = 0
if index - 1 < manhole - index:
	action += (index - 1) * 2 + manhole - index
else:
	action += (manhole - index) * 2 + index - 1
action += manhole * 2
action += 1
print(action)


def rli():
	return list(map(int, input().split()))

def main():
	(n, k) = rli()
	ans = n * 3
	if k != n and k != 1:
		ans += min(n - k, k - 1)
	print(ans)
main()


(n, k) = list(map(int, input().split()))
k2 = min(n - k, k - 1)
moves = n + k2 - 1
stones = n + 1
opening = n
print(moves + stones + opening)


from sys import stdin, stdout
(n, k) = map(int, stdin.readline().split())
k -= 1

def solve(n, k):
	if k == 0:
		return 4 + (n - 1) * 3 - 1
	else:
		k = min(k, n - k - 1)
		return 4 + (k - 1) * 3 - 1 + k + (n - k) * 3
stdout.write('{}\n'.format(solve(n, k)))


(n, k) = list(map(int, input().split()))
res = min(n - k, k - 1)
res += 2 + 4
res += 3 * (n - 2)
print(res)


(n, k) = map(int, input().split())
import cmath
if n - k < k - 1:
	print(n - k + 3 * n)
else:
	print(k - 1 + 3 * n)


nk = [int(x) for x in input().strip().split(' ')]
n = nk[0]
k = nk[1]
moves = 0
if n % 2 == 0:
	if k <= n // 2:
		moves += k - 1
	else:
		moves += n - k
elif k == n // 2:
	moves += k - 1
elif k < n // 2:
	moves += k - 1
else:
	moves += n - k
moves += 2
moves += 1
moves += 3
moves += (n - 2) * 3
print(moves)


(n, k) = tuple(map(int, input().split(' ')))
steps = 2 + 4 + 3 * (n - 2) + min(k - 1, n - k)
print(steps)


tokens = input().split()
n = int(tokens[0])
index = int(tokens[1])
total = 0
stepsEnd = min(index - 1, n - index)
total = total + stepsEnd + n - 1
total = total + n
total = total + 2 + n - 1
print(total)


(n, k) = map(int, input().split())
if k <= n / 2:
	x = k
else:
	x = n - k + 1
if n == 2:
	print(str(6))
else:
	print(3 * n + x - 1)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def quad(tup):
	(x, y) = tup
	if x > y:
		return -1
	if y > x:
		return 1
	else:
		return 0

def solve():
	(n, k) = sep()
	print(3 * n + min(k - 1, n - k))
solve()


(n, k) = map(int, input().split())
c1 = 3 * n
k -= 1
c = min(k, n - k - 1)
print(c1 + c)


(n, k) = [int(n) for n in input().split(' ')]
if k == 1:
	print(3 * n)
elif k == n:
	print(3 * n)
elif k <= int(n / 2):
	steps = 0
	steps += 3 * k - 1
	steps += k
	steps += (n - k) * 3
	print(steps)
else:
	steps = 0
	steps += (n - k + 1) * 3 - 1
	steps += n - k + 1
	steps += 3 * (k - 1)
	print(steps)


(n, k) = input().split()
n = int(n)
k = int(k)
if k - 1 > n - k:
	s = n - k
else:
	s = k - 1
print(n * 3 + s)


(n, k) = map(int, input().split())
ans = 2 * n + 1
ans += 2 * min(k - 1, n - k)
ans += max(k - 1, n - k)
print(ans)


import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def solve():
	(n, k) = num_input()
	print(min(k - 1, n - k) + 3 * n)
t = 1
for _ in range(t):
	solve()


(n, k) = [int(s) for s in input().split()]
ans = 0
ans += min(k - 1, n - k)
ans += n
ans += n - 1
ans += 1
ans += 2
ans += n - 2
print(ans)


(n, k) = map(int, input().strip().split())
res = 0
if k == 1 or k == n:
	res += 6 + 3 * (n - 2)
else:
	mid = int(n / 2)
	if k <= mid:
		res += 6 + (k - 2) * 3
		res += k - 1 + 3 * (n - k)
	else:
		k = 1 + n - k
		res += 6 + (k - 2) * 3
		res += k - 1 + 3 * (n - k)
print(res)


(x, y) = map(int, input().split())
print(x * 3 + min(x - y, y - 1))


def ans(n, k):
	if n == 2:
		return 6
	return min(k - 1, n - k) + 6 + 3 * (n - 2)
nk = list(map(int, input().strip().split()))
print(ans(nk[0], nk[1]))


(n, k) = map(int, input().split())
tot_moves = min(n - k, k - 1) + n - 1
tot_process = 2 * n + 1
tot_steps = tot_process + tot_moves
print(tot_steps)


(n, k) = map(int, input().split())
dist_left = k - 1
dist_right = n - k
ans = n + (n + 1) + min(dist_left, dist_right) + (n - 1)
print(ans)


(n, k) = map(int, input().split())
if n == 2:
	print('6')
else:
	ans = 2 * min(k - 1, n - k) + max(k - 1, n - k) + 5 + 2 * (n - 2)
	print(ans)


(n, k) = map(int, input().split())
print(min(3 * n - 1 + k, n * 4 - k))


(x, y) = map(int, input().split())
if x - y < y:
	print(4 * (x - y) + 3 * y)
else:
	print(4 * (y - 1) + 3 * (x - y + 1))


(a, b) = map(int, input().split())
t = min(b - 1, a - b)
if a == 1:
	print(0)
elif b != a and b != 1:
	print(3 * a + t)
else:
	print(3 * a)


(n, k) = (int(t) for t in input().split(' '))
print(n * 3 + min(k - 1, n - k))


import sys
I = lambda : list(map(int, input().split()))
(n, k) = I()
if k == 1 or k == n:
	print(2 * n + n)
else:
	print(3 * n + min(k - 1, abs(n - k)))


(n, k) = map(int, input().split())
temp = n / 2
if temp >= k:
	result = k - 1 + 2 + 1 + 3 + (n - 2) * 3
else:
	result = n - k + 2 + 1 + 3 + (n - 2) * 3
print(result)


line = input()
n = int(line.split(' ')[0])
k = int(line.split(' ')[1])
if k > n / 2:
	print(n + 1 + n + (n - k + (n - 1)))
else:
	print(n + 1 + n + (k - 1 + (n - 1)))


str = input().strip().split(' ')
(n, k) = (int(str[0]), int(str[1]))
ans = 3 * n + min(k - 1, n - k)
print(ans)


from sys import stdin, stdout
from collections import *
from math import ceil, floor, log, gcd
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():
	(n, k) = mp()
	ans = 3 * n + min(n - k, k - 1)
	pr(ans)
for _ in range(1):
	solve()


(n, k) = [int(r) for r in input().split()]
print(n + n + 1 + n - 1 + min(n - k, k - 1))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	(n, k) = LI()
	r = n * 2 + 1
	m = min(k - 1, n - k)
	return r + m + n - 1
print(main())


(N, K) = map(int, input().split())
print(3 + 2 * (N - 1) + min(K - 1, N - K) + (N - 1))


(n, k) = map(int, input().split())
counts = 3 + (n - 1) * 2
aux = min(k - 1, n - k)
counts += n - 1 + aux
print(counts)


(n, k) = map(int, input().split())
k -= 1
go_to_border = min(k, n - k - 1)
more = 3 * n
print(go_to_border + more)


p = input().rstrip().split(' ')
a = int(p[0])
b = int(p[1])
g = b - 1
G = a - b
if g <= G:
	A = 2
	for i in range(0, g):
		A += 1
		if i == 0:
			A += 3
		else:
			A += 2
	A += b
	for i in range(b, a):
		if i != b:
			A += 1
		A += 2
	if b == 1:
		print(A + 1)
	else:
		print(A)
else:
	A = 2
	for i in range(0, G):
		A += 1
		if i == 0:
			A += 3
		else:
			A += 2
	A += a - b
	for i in range(0, b - 1):
		A += 3
	if b == a:
		print(A + 1)
	else:
		print(A)


from sys import *
(n, k) = map(int, stdin.readline().split())
ans = 3
x = min(k - 1, n - k)
y = max(k - 1, n - k)
ans += 4 * x + 3 * y
print(ans)


(n, k) = [int(s) for s in input().split()]
if k == 1 or k == n:
	print(4 + 3 * (n - 1) - 1)
else:
	print(4 + min(k - 2, n - k - 1) + 3 * (n - 1))


mi = lambda : [int(i) for i in input().split()]
(n, k) = mi()
if n == 2:
	res = 6
elif k == 1 or k == n:
	res = 6 + (n - 2) * 3
else:
	u = k - 1
	res = 5 + 3 * u + u + 1 + (n - u - 2) * 3
	k = n - k + 1
	u = k - 1
	res = min(res, 5 + 3 * u + u + 1 + (n - u - 2) * 3)
print(res)


s = input()
s1 = s.split(' ')
n = int(s1[0])
k = int(s1[1])
ans = 0
if n % 2 == 0:
	if k == n:
		ans = 3 * n
	elif k <= n / 2:
		ans = 3 * n + k - 1
	elif k > n / 2:
		ans = 4 * n - k
elif k == n:
	ans = 3 * n
elif k <= n // 2:
	ans = 3 * n + k - 1
elif k > n / 2:
	ans = 4 * n - k
print(ans)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
from collections import *
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True

def main():
	(n, k) = mi()
	arr = [1] * n
	mv = 0
	if len(arr[:k]) <= len(arr[k:]):
		mv = (k - 1) * 2 + k
		mv += (n - k) * 2 + n + 1
	else:
		mv = (n - k) * 2 + (n - k)
		mv += k - 1 + k + 1 + n
	print(mv)
main()


import sys
from math import floor, ceil, log2
inp = lambda : sys.stdin.readline().strip()
(n, k) = map(int, inp().split())
minv = min(k - 1, n - k)
ans = n * 2 + 1 + n - 1 + minv
print(ans)


(N, K) = map(int, input().split())
S = [1] * N
P = [False] * N
if K == 1 or K == N:
	print(N * 3)
else:
	an = 2
	minS = K - 1
	maxS = N - K
	(minS, maxS) = (min(minS, maxS), max(minS, maxS))
	an += 3 * minS
	an += minS + 1 + 3 + 3 * (maxS - 1)
	print(an)


(n, k) = map(int, input().split())
if k == 1 or k == n:
	steps = 2 + 4 + (n - 2) * 3
elif k == 2 or k == n - 1:
	steps = 5 + 2 + (n - 2) * 3
else:
	steps = 6
	if k > n // 2 + 1:
		k = n - k + 1
	steps += k + 2
	steps += (n - 3) * 3
print(steps)


(n, k) = map(int, input().split())
ans = 2 * n + 1
per = min(n - k, k - 1)
per += n - 1
ans += per
print(ans)


arr = list(map(int, input().split()))
val = 2 * arr[0] + 1 + 2 * min(arr[0] - arr[1], arr[1] - 1) + max(arr[0] - arr[1], arr[1] - 1)
print(val)


(n, k) = map(int, input().split())
if k - 1 < n - k:
	print(n + (k - 1 + n - 1) + n + 1)
else:
	print(n + (n - k + n - 1) + n + 1)


[n, k] = list(map(int, input().split()))
x = n - k
y = n - x - 1
if x >= y:
	step = 3 * n + y
else:
	step = 3 * n + x
print(step)


(n, k) = [int(p) for p in input().split()]
print(3 * n + min(n - k, k - 1))


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from itertools import *
from collections import Counter
(N, K) = map(int, stdin.readline().rstrip().split())
ans = 3 * N
if K == 1 or K == N:
	ans = 3 * N
else:
	ans += min(N - K, K - 1)
print(ans)


(n, k) = [int(i) for i in input().split()]
z = n + n - 1 + n + 1
if k > n - k:
	print(z + n - k)
else:
	print(z + k - 1)


(n, k) = map(int, input().split())
if n == 1:
	print(2)
else:
	sure = n + n + 1 + n - 1
	if k != 1 and k != n:
		sure += min(n - k, k - 1)
	print(sure)


from sys import stdin, stdout
from math import *
(n, m) = map(int, input().split())
ans = 0
if 1 < m < n:
	m = min(m, n - m + 1)
	ans = m * 3 - 1 + m
	ans += (n - m) * 3
	print(ans)
elif m == 1 or m == n:
	m = 1
	print(n * 3)


gi = lambda : list(map(int, input().strip().split()))
(n, K) = gi()
a = (n - K) * 4 + 4 + (K - 1) * 3
b = 4 + (K - 1) * 4 + (n - K) * 3
print(min(a, b) - 1)


import sys, math, queue
sys.setrecursionlimit(1000000)
(n, k) = map(int, input().split())
print(3 * n + min(k - 1, n - k))


(n, k) = map(int, input().split())
k = min(k, n - k + 1)
ans = 0
if k > 1:
	ans = 3 * k
	ans += k
	k = n - k
	ans += 3 * k - 1
else:
	ans = 3 * n
print(ans)


import math
inarr = lambda : map(int, input().split())
for _ in range(1):
	(n, k) = map(int, input().split())
	ans = n - 1 + min(n - k, k - 1) + n * 2 + 1
	print(ans)


(n, k) = map(int, input().split())
q = min(n - k, k - 1) + 3 * n
print(q)


from sys import setcheckinterval, stdin
setcheckinterval(1000)
iin = lambda : int(stdin.readline())
lin = lambda : list(map(int, stdin.readline().split()))
(n, k) = lin()
(x, y) = (k, n - k + 1)
ans = 6
mn = min(x, y)
if mn <= 2:
	if mn == 2:
		ans += 1
else:
	ans += mn - 2 + 1
n -= 2
ans += n * 3
print(ans)


(n, k) = input().split()
n = int(n)
k = int(k)
if k <= n / 2:
	print(n * 3 + k - 1)
else:
	print(n * 3 + n - k)


(n, k) = map(int, input().split())
count = 0
coins = [1 for i in range(n)]
stones = [1 for i in range(n)]
if k <= n // 2:
	count = 3 * n + k - 1
else:
	count = 4 * n - k
print(count)


(n, k) = map(int, input().split())
ans = n * 3
u = min(n - k, k - 1)
ans = ans + u
print(ans)


(a, b) = map(int, input().split())
s = 3 * a
if a - b < b - 1:
	s = s + a - b
else:
	s = s + b - 1
print(s)


(n, k) = list(map(int, input().split()))
if k == 1:
	print(3 * (n - 1) + 3)
elif k == n:
	print(3 * (n - 1) + 3)
else:
	shorter = min(k - 1, n - k)
	longer = max(k - 1, n - k)
	out = 0
	out += shorter * 3 + shorter + longer * 3 + 3
	print(out)


x = list(map(int, input().split()))
p = x[0] * 3
p += min(x[0] - x[1], x[1] - 1)
print(p)


(a, b) = map(int, input().split())
if b != 1 and a - b != 0:
	if a - b < b:
		print((a - b) * 3 + 2 + (a - b + 1) + (b - 1) * 3)
	else:
		print((b - 1) * 3 + 2 + b + (a - b) * 3)
else:
	print(a * 3)


import collections
(n, k) = map(int, input().split())
if k == 1 or k == n:
	ans = 4 + 3 * (n - 1) - 1
else:
	k = min(k, n - k + 1)
	ans = 4 + (n - 1) * 3 - 2 + k
print(ans)


import getpass
import math
import sys
import string
import re
import math
import random
from decimal import Decimal, getcontext

def ria():
	return [int(i) for i in input().split()]
if getpass.getuser() != 'frohenk':
	filename = 'half'
else:
	sys.stdin = open('input.txt')
(n, k) = ria()
rcks = n + 1
mny = n
mvs = min((k - 1) * 2 + (n - k), k - 1 + (n - k) * 2)
if k == 1:
	mvs = n - 1
if k == n:
	mvs = n - 1
print(mvs + rcks + mny)


import sys
(n, s) = map(int, input().split())
if s == 1 or s == n:
	print(n * 3)
	sys.exit()
sm = s - 1
lm = n - s
if sm <= lm:
	ans = 6 + (sm - 1) * 4 + 1 + lm * 3
else:
	ans = 6 + (lm - 1) * 4 + 1 + sm * 3
print(ans)


(n, k) = map(int, input().split(' '))
s = 0
if n == 2:
	print(6)
	exit(0)
s += n
s += n
work = 2 * min(k - 1, n - k)
work += max(k - 1, n - k)
s += work
s += 1
print(s)


(n, k) = map(int, input().split())
out = n * 2 + 1
out += n + min(k - 1, n - k) - 1
print(out)


(n, k) = map(int, input().split())
a = min(k - 1, n - k)
b = a + n - 1
print(n + 1 + n + b)


(n, k) = list(map(int, input().split()))
myrange = min(n - k, k)
if k == n:
	print(n + n - 1 + n - 1 + 2)
elif k == 1:
	print(n + n - 1 + 2 + n - 1)
elif k - 1 <= n - k:
	print(k + k - 1 + 2 + k - 1 + k - 1 + 3 * (n - k))
else:
	print(n - k + n - k + 1 + 2 + n - k + n - k + 3 * (k - 1))


(n, k) = map(int, input().split())
x = min(k - 1, n - k)
y = max(k - 1, n - k)
print(x * 2 + y + 2 * n + 1)


(n, k) = map(int, input().split())
mn = min(k - 1, n - k)
print(3 * n + mn)


(a, b) = map(int, input().split())
n = (a - 2) * 2 + 5
m = min(b - 1, a - b) * 2 + max(b - 1, a - b)
print(n + m)


(n, k) = [int(s) for s in input().split()]
print(3 * n + min([n - k, k - 1]))


from sys import stdin
input = stdin.readline
(n, k) = map(int, input().split())
print(3 * n + min(k - 1, n - k))


(n, k) = tuple(map(int, input().split()))
a = min(k - 1, n - k)
b = max(k - 1, n - k)
moves = 3 + a * 3
moves += a + 3 * b
print(moves)


def main():
	(n, k) = map(int, input().split())
	short = min(n - k, k - 1)
	print(short + n - 1 + n + 1 + n)
main()


X = list(map(int, input().split()))
print(6 + (X[0] - 2) * 3 + min(X[1] - 1, X[0] - X[1]))


(n, k) = list(map(int, input().split()))
if k == 1 or k == n:
	val = 6 + (n - 2) * 3
else:
	val = min(k - 1, n - k) + 6 + (n - 2) * 3
print(val)


(n, k) = [int(e) for e in input().split()]
move_to_all_manhole = min(n - k, k - 1) + (n - 1)
open_manhole = n
throw = n + 1
print(throw + move_to_all_manhole + open_manhole)


def main():
	[n, k] = list(map(int, input().split(' ')))
	left = k - 1
	right = n - k
	minimum = min(left, right)
	moves = n - 1 + minimum
	print(moves + n + n + 1)
main()


from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import defaultdict
from itertools import *
import functools
import sys
import math
import random
MAX = sys.maxsize
MAXN = 10 ** 6 + 10
MOD = 10 ** 9 + 7

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b, x, y):
	return abs(a - x) + abs(b - y)

def numIN(x=' '):
	return map(int, sys.stdin.readline().strip().split(x))

def charIN():
	return sys.stdin.readline().strip().split()

def trace(x, y):
	print(x, '=', y)
(n, k) = numIN()
ans = 2 * (n - 1) + 3 + n - 1
if k != 1 and k != n:
	print(ans + min(k - 1, n - k))
else:
	print(ans)


from collections import deque, Counter, OrderedDict
from heapq import nsmallest, nlargest, heapify, heappop, heappush, heapreplace
from math import ceil, floor, log, log2, sqrt, gcd, factorial, pow, pi
from bisect import bisect_left, bisect_right

def binNumber(n, size=4):
	return bin(n)[2:].zfill(size)

def iar():
	return list(map(int, input().split()))

def ini():
	return int(input())

def isp():
	return map(int, input().split())

def sti():
	return str(input())

def par(a):
	print(' '.join(list(map(str, a))))

def tdl(outerListSize, innerListSize, defaultValue=0):
	return [[defaultValue] * innerListSize for i in range(outerListSize)]

def sts(s):
	s = list(s)
	s.sort()
	return ''.join(s)

def bis(a, x):
	i = bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return [i, True]
	else:
		return [-1, False]

class pair:

	def __init__(self, f, s):
		self.fi = f
		self.se = s

	def __lt__(self, other):
		return (self.fi, self.se) < (other.fi, other.se)
(n, k) = isp()
if k == 1 or k == n:
	print(3 * n)
	quit()
ans = 0
if n % 2 == 0:
	if k <= n // 2:
		ans = 3 * k - 1 + k + 3 + 3 * (n - k - 1)
	else:
		ans = 3 * (n - k + 1) - 1 + n - k + 1 + 3 + 3 * (n - (n - k + 1) - 1)
elif k <= n // 2 + 1:
	ans = 3 * k - 1 + k + 3 + 3 * (n - k - 1)
elif k > n // 2 + 1:
	ans = 3 * (n - k + 1) - 1 + n - k + 1 + 3 + 3 * (n - (n - k + 1) - 1)
print(ans)


(n, k) = map(int, input().split(' '))
l_d = k - 1
r_d = n - k
b = max(l_d, r_d)
s = min(l_d, r_d)
distance = 2 * s + b
r = 2 * n + 1 + distance
print(r)


(c, d) = map(int, input().split())
if c != d and d != 1:
	print(6 + (c - 2) * 3 + min(d - 1, c - d))
else:
	print(6 + (c - 2) * 3)


import sys
import heapq
import math
from enum import Enum
lines = sys.stdin.read().splitlines()
(n, k) = map(int, lines[0].split(' '))
print(2 * n + 1 + min(k - 1, n - k) * 2 + max(k - 1, n - k))


def main():
	(n, k) = map(int, input().split())
	if k == 1 or k == n:
		print(3 * n)
	else:
		min_move = min(k - 1, n - k)
		total_move = min_move + n - 1
		total_stone = n + 1
		print(total_move + total_stone + n)
main()


(n, k) = [int(_) for _ in input().split()]
print(n * 3 + min(abs(n - k), k - 1))


def main():

	def cmp_to_key(mycmp):

		class K(object):

			def __init__(self, obj, *args):
				self.obj = obj

			def __lt__(self, other):
				return mycmp(self.obj, other.obj) < 0

			def __gt__(self, other):
				return mycmp(self.obj, other.obj) > 0

			def __eq__(self, other):
				return mycmp(self.obj, other.obj) == 0

			def __le__(self, other):
				return mycmp(self.obj, other.obj) <= 0

			def __ge__(self, other):
				return mycmp(self.obj, other.obj) >= 0

			def __ne__(self, other):
				return mycmp(self.obj, other.obj) != 0
		return K
	(n, k) = map(int, input().split())
	print(3 * n + min(n - k, k - 1))
for qwerty in range(1):
	main()


s = input()
s = s.split()
a = int(s[0])
b = int(s[1])
count = a * 3
if b > a // 2:
	count = count + a - b
elif b <= a // 2:
	count = count + b - 1
print(count)


(n, k) = map(int, input().split())
count = 0
if k == 1 or k == n:
	count = 5 + 3 * (n - 2) + 1
else:
	if k > n // 2:
		k = n - k + 1
	count = 5 + 3 * (k - 2) + 1 + k + 2 + 3 * (n - k - 1)
print(count)


import sys
import math
from sys import stdin, stdout

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

def get_ints_in_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def Solution(arr, n):
	pass

def main():
	(n, k) = get_ints_in_variables()
	print(3 * n + min(n - k, k - 1))
main()


from math import inf, sqrt, floor, ceil
from collections import Counter, defaultdict, deque
from heapq import heappush as hpush, heappop as hpop, heapify as h
from operator import itemgetter
from itertools import product
(n, k) = map(int, input().split())
if k == 1 or k == n:
	print(3 * n)
else:
	print(min(n + n + 1 + k - 1 + k - 1 + n - k, n + n + 1 + n - k + n - k + k - 1))


import sys
(n, k) = map(int, input().split())
print(n + 1 + n + (n - 1) + min(k - 1, n - k))


def main():
	(n, k) = map(int, input().split())
	ans = min(k - 1, n - k)
	ans += n - 1
	ans += n + n + 1
	print(ans)
main()


(n, k) = map(int, input().split())
(ans, pos) = (0, 0)
pos = min(k - 1, abs(n - k))
print(3 * n + pos)


(n, k) = map(int, input().split())
total = min(k - 1, n - k) + n - 1 + 5
n -= 2
total += n * 2
print(total)


(n, k) = list(map(int, input().split()))
(dist_l, dist_r) = (k - 1, n - k)
line_moves = n - 1
pick_moves = n
stone_moves = n + 1
moves = min(dist_l, dist_r) + line_moves + pick_moves + stone_moves
print(moves)


a = list(map(int, input().split()))
n = a[0]
m = a[1]
print(3 * n + min(m - 1, n - m))


num_stones = [1] * 5010
has_coin = [True] * 5010
[n, k] = [int(x) for x in input().split()]
k -= 1
LEFT = -1
RIGHT = 1
coins_picked = 0
if n / 2 <= k:
	movement = RIGHT
else:
	movement = LEFT
moves = 0
while coins_picked != n:
	if has_coin[k]:
		if num_stones[k] != 0:
			num_stones[k] -= 1
			num_stones[k - movement] += 1
		else:
			has_coin[k] -= 1
			coins_picked += 1
	else:
		if movement == LEFT and k == 0:
			movement = RIGHT
		elif movement == RIGHT and k == n - 1:
			movement = LEFT
		k += movement
	moves += 1
print(moves)


import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)
isdebug = False
try:
	import pylint
	import numpy

	def dprint(*args, **kwargs):
		print(*args, file=sys.stderr)
	dprint('debug mode')
	isdebug = True
except Exception:

	def dprint(*args, **kwargs):
		pass

def red_inout():
	inId = 0
	outId = 0
	if not isdebug:
		inId = 0
		outId = 0
	if inId > 0:
		dprint('use input', inId)
		try:
			f = open('input' + str(inId) + '.txt', 'r')
			sys.stdin = f
		except Exception:
			dprint('invalid input file')
	if outId > 0:
		dprint('use output', outId)
		try:
			f = open('stdout' + str(outId) + '.txt', 'w')
			sys.stdout = f
		except Exception:
			dprint('invalid output file')
		atexit.register(lambda : sys.stdout.close())
if isdebug and len(sys.argv) == 1:
	red_inout()

def getIntList():
	return list(map(int, input().split()))

def solve():
	pass
T_ = 1
for iii_ in range(T_):
	(N, K) = getIntList()
	r = N + 1
	r += N
	r += N
	r += min(K - 1, N - K) - 1
	print(r)


import math
import bisect

def argsort(ls):
	return sorted(range(len(ls)), key=ls.__getitem__)

def f(p=0):
	if p == 0:
		return int(input())
	if p == 1:
		return map(int, input().split())
	elif p == 2:
		return list(map(int, input().split()))
	else:
		return sorted(list(map(int, input().split())))
(n, k) = f(1)
mx = max(k - 1, n - k)
mn = min(k - 1, n - k)
res = mn * 2 + mx + (3 + (n - 2)) + n
print(res)


cnt = lambda s, x: s.count(x)
ii = lambda : int(input())
si = lambda : input()
f = lambda : map(int, input().split())
dgl = lambda : list(map(int, input()))
il = lambda : list(map(int, input().split()))
(n, k) = f()
if k == 1 or k == n:
	st = 6 + (n - 2) * 3
else:
	if k > n // 2:
		k = n - k + 1
	st = 6 + (k - 2) * 3 + k + (n - k) * 2 + n - k - 1
print(st)


t = input().split(' ')
n = int(t[0])
k = int(t[1])
m = min(k - 1, n - k)
print(3 * n + m)


def go():
	(n, k) = map(int, input().split(' '))
	return min(n - k, k - 1) + 3 * n
print(go())


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
(nb_manhole, position) = RMI()
print(nb_manhole * 3 + min(position - 1, nb_manhole - position))


TN = 1

def solution():
	(n, k) = map(int, input().split())
	if k > n - k:
		k = n - k + 1
	ans = 3 * n + k - 1
	print(ans)
while TN != 0:
	solution()
	TN -= 1


(n, k) = [int(x) for x in input().split()]
right = n - k
left = k - 1
if k == 1:
	print(6 + 3 * (n - 2))
elif k == n:
	print(6 + 3 * (left - 1))
else:
	f = 6 + 3 * (left - 1) + left + 3 * right
	s = 6 + 3 * (right - 1) + right + 3 * left
	print(min(f, s))


(n, k) = map(int, input().split())
cost = 0
k = min(k, n - k + 1)
x = k
while x >= 1:
	x -= 1
	cost += 3
cost -= 1
cost += k - 1
cost += n - k
cost += 2 * (n - k) + 1
print(cost)


(a, b) = [int(i) for i in input().split()]
q = min(a - b, b - 1)
ans = q + 6 + (a - 2) * 3
print(ans)


(a, b) = map(int, input().split())
if (a + 1) // 2 < b:
	b = 1 + a - b
if a == b:
	k = b - 1
else:
	k = (b - 1) * 2 + (a - b)
print(k + 1 + 2 * a)


(n, k) = map(int, input().split())
moves = 2 * n + 1
if k == 1 or k == n:
	x = n - 1
else:
	x = min((k - 1) * 2, (n - k) * 2) + max(k - 1, n - k)
moves += x
print(moves)


from sys import maxsize, stdout, stdin, stderr
mod = int(1000000000.0 + 7)

def I():
	return int(stdin.readline())

def lint():
	return [int(x) for x in stdin.readline().split()]

def S():
	return input().strip()

def grid(r, c):
	return [lint() for i in range(r)]
from collections import defaultdict
import math
(n, k) = lint()
print(3 * n + min(k - 1, n - k))


(n, k) = [int(i) for i in input().split()]
if k == n:
	k = 1
if k == 1:
	print(int((n - 1) * 3 + 3))
else:
	print(int(min(k - 1, n - k) * 4 + 3 + 3 * max(k - 1, n - k)))


(n, k) = map(int, input().split())
ans = 0
if k - 1 < n - k:
	while k > 1:
		k -= 1
		ans += 1
	ans += 4
	k += 1
	while k <= n:
		k += 1
		ans += 3
	ans -= 1
else:
	while k < n:
		k += 1
		ans += 1
	ans += 4
	k -= 1
	while k >= 1:
		k -= 1
		ans += 3
	ans -= 1
print(ans)


(n, k) = map(int, input().split())
if k > n // 2:
	a = int(n - k)
else:
	a = int(k - 1)
if k == 1:
	print(n * 3)
elif k == n:
	print(n * 3)
else:
	print(n * 3 + a)


(n, k) = map(int, input().split())
co = n * 3 + min(k - 1, n - k)
print(co)


(a, k) = map(int, input().split())
if k == 1 or k == a:
	print(a * 3)
else:
	print(3 * a + min(a - k, k - 1))


(n, k) = map(int, input().split())
if n == 2:
	print(6)
	exit()
if k > n // 2:
	k = n - k + 1
kol = n - 2 + k + 2 * (n - 1) + 3
print(kol)


import sys
import math, bisect
sys.setrecursionlimit(10 ** 5)
from collections import defaultdict
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, OrderedDict

def I():
	return int(sys.stdin.readline())

def neo():
	return map(int, sys.stdin.readline().split())

def Neo():
	return list(map(int, sys.stdin.readline().split()))
(n, k) = neo()
Ans = 3 * n
if k != 1 and k != n:
	Ans += min(k - 1, n - k)
print(Ans)


(n, k) = map(int, input().split())
count = 0
count += n * 2
count += n - 1
if 1 < k <= n // 2:
	count += k - 1
elif n // 2 < k < n:
	count += n - k
print(count + 1)


(n, k) = [int(i) for i in input().split(' ')]
if k != n and k != 1:
	if round(n / 2) >= k:
		print(k * 4 + (n - k) * 3 - 1)
	else:
		print((n - k) * 4 + k * 3)
else:
	print(n * 3)


test = list(map(int, input().split(' ')))
n = test[0]
k = test[1]
c = n
if n == 2:
	print(3 * n)
else:
	c = c + n + min(k - 1, n - k) - 1
	c = c + n + 1
	print(c)


(n, k) = tuple(map(int, input().split()))
left = k - 1
right = n - k
if left < right:
	print(left + 2 + 1 + 2 + 1 + (left - 1) * 3 + right * 3)
else:
	print(right + 2 + 1 + 2 + 1 + (right - 1) * 3 + left * 3)


(n, k) = map(int, input().split())
open = n
walk = min(k - 1, n - k) + n - 1
push = n + 1
print(open + walk + push)


(n, k) = map(int, input().split())
if n == 2:
	print(6)
	exit()
print(3 * n + min(abs(1 - k), abs(n - k)))


(n, k) = map(int, input().split())
if n - k + 1 >= k:
	z = k - 1 + 2 * n + 1 + n - 1
else:
	z = n - k + 2 * n + 1 + n - 1
print(z)


(n, k) = [int(i) for i in input().split()]
if k != 1 and k != n:
	ans = n * 2 + min(k - 1, n - k) + n
else:
	ans = n * 3
print(ans)


def f(l):
	(n, k) = l
	return 3 * n + min(k - 1, n - k)
l = list(map(int, input().split()))
print(f(l))


def manhole_game(n, i):
	moves = 0
	if i != 1 and i != n:
		dist = abs(n - i)
		dist2 = abs(i - 1)
		moves += min(dist, dist2)
	moves += n - 1
	moves += n * 2 + 1
	return moves
(n, i) = list(map(int, input().split()))
print(manhole_game(n, i))


(c, d) = map(int, input().split())
print(6 + (c - 2) * 3 + min(d - 1, c - d))


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))
(n, k) = list(map(int, input().split()))
s = n
s += n + 1
s += min(k - 1, n - k)
s += n - 1
print(s)


num = [int(x) for x in input().split(' ')]
(n, k) = (num[0], num[1])
if k >= n // 2 + 1:
	ans = 4 * (n - k) + 3 * (k - 1) + 3
else:
	ans = 4 * (k - 1) + 3 * (n - k) + 3
print(ans)


MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(n, k) = I()
ans = min(k - 1, n - k)
print(ans + 6 + (n - 2) * 3)


(n, k) = [int(x) for x in input().split()]
ans = n + (n + 1)
if k == n:
	ans += n - 1
else:
	ans += n - 1 + min(n - k, k - 1)
print(ans)


(n, k) = map(int, input().split())
s = 0
s += min(n - k + n - 1, k - 1 + n - 1)
s += n - 1 + 2
s += n
print(s)


str_inp = input().split()
(n, k) = (int(str_inp[0]), int(str_inp[1]))
print(3 * n + min(k - 1, n - k))


def main():
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	if k == n:
		print(n * 3)
	elif k == 1:
		print(n * 3)
	elif k <= n / 2:
		print(1 * (k - 1) + n * 3)
	else:
		print(1 * (n - k) + n * 3)
main()


(n, k) = map(int, input().split())
eds = min(k - 1, n - k)
edl = max(k - 1, n - k)
ans = 2 * (n - 1) + 3 + 2 * eds + edl
print(ans)


(n, k) = map(int, input().split(' '))
res = 3 * n
res += min(n - k, k - 1)
print(res)


(n, k) = map(int, input().split())
index = k - 1
total_move = n
short_move = min(index, n - index - 1)
total_move += short_move + (n - 1)
total_move += 3 + max(0, n - 2)
print(total_move)


(n, k) = [int(item) for item in input().split()]
if k == n or k == 1:
	ans = n - 1 + 1 + 1 + n - 1 + n
else:
	ans = 1 + 1 + (n - 1) + (min(n - (k - 1) - 1, k - 1) + n - 1) + n
print(ans)


data = input().split()
hole = int(data[0])
k = int(data[1])
stone = hole * [1]
steps = hole
if k <= hole // 2 or k == (hole + 1) / 2:
	steps = steps + k - 1 + hole - 1
elif k > hole // 2:
	steps = steps + hole - k + hole - 1
steps = steps + hole + 1
print(steps)


(a, b) = map(int, input().split())
print(2 * a + 1 + (a - 1) + min(b - 1, a - b))


from sys import stdin
(n, k) = map(int, stdin.readline().split())
moves = n - 1 + min(n - k, k - 1)
ans = 1 + moves + 2 * n
print(ans)


def computer_games_problem():
	(n, k) = input().split(' ')
	(n, k) = (int(n), int(k))
	answer = min(k - 1, n - k) + 3 * n
	print(answer)
	return
computer_games_problem()


(n, k) = map(int, input().split())
if k == 1:
	ans = 6 + (n - 2) * 3
elif k == n:
	ans = 6 + (n - 2) * 3
else:
	ans1 = 6 + (k - 2) * 3 + (k - 1) + (n - k) * 3
	ans2 = 6 + (n - k - 1) * 3 + (n - k) + (k - 1) * 3
	ans = min(ans1, ans2)
print(ans)


def ktobolshepravoililevoililevoilipravo(tg, kh):
	return tg < kh
(n, k) = map(int, input().split())
pravoililevo = k - 1
levoilipravo = n - k
if ktobolshepravoililevoililevoilipravo(pravoililevo, levoilipravo):
	resheniesuda = 2 * pravoililevo + levoilipravo + 2 * n + 1
else:
	resheniesuda = 2 * levoilipravo + pravoililevo + 2 * n + 1
print(resheniesuda)


import math
(n, k) = map(int, input().split(' '))
base = 3 * n
if k > math.ceil(n / 2):
	ans = base + n - k
else:
	ans = base + k - 1
print(ans)


(n, k) = map(int, input().split())
x = (n - 1) * 2 + 3
if k == 1 or k == n:
	x += n - 1
elif k - 1 <= n - k:
	x += (k - 1) * 2
	x += n - k
else:
	x += (n - k) * 2
	x += k - 1
print(x)


(n, k) = map(int, input().split())
diff1 = k - 1
diff2 = n - k
ans = 2
if diff1 <= diff2:
	ans += 4 * diff1
	ans += 1
	ans += 3 * diff2
else:
	ans += 4 * diff2
	ans += 1
	ans += 3 * diff1
print(ans)


(n, k) = input().split()
n = int(n)
k = int(k)
ans = 2 + 1
ans += 3 * (n - 1)
d1 = n - k
d2 = k - 1
d = min(d1, d2)
ans += d
print(ans)


(n, k) = map(int, input().split())
x = k - 1
y = n - k
if x == 0 or y == 0:
	print(3 * (x + y + 1))
else:
	print(3 * (x + y + 1) + min(x, y))


import sys

def rint():
	return map(int, sys.stdin.readline().split())
(n, k) = rint()
ans = 0
ans += n
minl = min(k - 1, n - k)
maxl = max(k - 1, n - k)
ans += minl * 2 + maxl
ans += n + 1
print(ans)


def main():
	(n, k) = map(int, input().split())
	moves = 2 * n
	moves += 1
	moves += min(k - 1, n - k)
	moves += n - 1
	print(moves)
main()


(q, w) = map(int, input().split())
z = q + (q + min(q - w, w - 1)) + q
print(z)


from sys import stdin, stdout

def inp():
	return int(stdin.readline())

def minp():
	return map(int, stdin.readline().rstrip().split())

def linp():
	return list(minp())

def main():
	(n, k) = minp()
	move = 0
	if k == n:
		move = 3 * k
	elif k != 1:
		if k <= n / 2:
			move += 3 * k + k - 1
			move += n - k + n - k + n - k
		else:
			k = n - k + 1
			move += 3 * k + k - 1
			move += n - k + n - k + n - k
	else:
		move = 3 * n
	print(move)
main()


(n, i) = map(int, input().split())
if i > (n + 1) / 2:
	i = n - i + 1
	print(2 * (n - 1) + 3 + n - 2 + i)
else:
	print(2 * (n - 1) + 3 + n - 2 + i)


(n, k) = map(int, input().split())
ans1 = 2 * n + 1
ans2 = 0
if k <= n / 2:
	ans2 = k * 2 - 2 + n - k
else:
	ans2 = (n - k) * 2 + k - 1
print(ans1 + ans2)


n = input().split(' ')
cur = int(n[1])
n = int(n[0])
print(n * 3 + min(cur - 1, n - cur))


(n, k) = map(int, input().split())
short = min(n - k, k - 1)
not_short = max(n - k, k - 1)
path = short * 2 + not_short
result = 2 * n + 1 + path
print(result)


(n, k) = map(int, input().split())
num = 0
if k == n:
	print(n * 3)
else:
	print(n * 3 + min(abs(n - k), k - 1))


(n, k) = map(int, input().split())
a = []
for i in range(n + 1):
	a.append(1)
initial = k
s = 0
if k > n // 2:
	for i in range(k, n + 1, 1):
		if i == k:
			final = i
			s = s + a[i] + 1 + (final - initial)
			p = a[i]
			a[i] = 0
			if k + 1 <= n:
				a[k + 1] += p
			else:
				a[k - 1] += p
			initial = i
		else:
			final = i
			s = s + a[i] + 1 + abs(final - initial)
			p = a[i]
			a[i] = 0
			a[k] += p
			initial = i
	for i in range(k - 1, 0, -1):
		final = i
		s = s + a[i] + 1 + abs(final - initial)
		p = a[i]
		a[i] = 0
		a[k] += p
		initial = i
	print(s)
else:
	for i in range(k, 0, -1):
		if i == k:
			final = i
			s = s + a[i] + 1 + abs(final - initial)
			p = a[i]
			a[i] = 0
			if k - 1 >= 1:
				a[k - 1] += p
			else:
				a[k + 1] += p
			initial = i
		else:
			final = i
			s = s + a[i] + 1 + abs(final - initial)
			p = a[i]
			a[i] = 0
			a[k] += p
			initial = i
	for i in range(k + 1, n + 1, 1):
		final = i
		s = s + a[i] + 1 + abs(final - initial)
		a[i] = 0
		a[k] += p
		initial = i
	print(s)


(n, i) = (int(p) for p in input().split())
if i <= n - i:
	moves = (i - 1) * 2 + n - i
else:
	moves = (n - i) * 2 + i - 1
print(n + 1 + n + moves)


(n, k) = [int(x) for x in input().split()]
if k - 1 < n - k:
	p = k - 1
else:
	p = n - k
print(2 * n + 1 + (n - 1) + p)


(n, k) = map(int, input().split())
su = 2
if int(n / 2) >= k:
	kk = k
	while kk - 1:
		su += 3
		kk -= 1
	su += k - 1
	while n != k:
		su += 3
		k += 1
else:
	kk = k
	while n != kk:
		su += 3
		kk += 1
	su += n - k
	while k - 1:
		su += 3
		k -= 1
print(su + 1)


(n, k) = list(map(int, input().split()))
a = n - 1
b = k - 1
dist = 0
if a - b > b:
	dist = 2 * b + a - b
else:
	dist = 2 * (a - b) + b
turn = 3 + (n - 2) + n + dist
print(turn)


import heapq
import sys
from collections import defaultdict, Counter
from functools import reduce
(n, k) = list(map(int, input().split()))
print(n + n + 1 + 2 * min(k - 1, n - k) + max(k - 1, n - k))


import sys
n = 0
k = 0
for line in sys.stdin:
	(n, k) = [int(i) for i in line.split()]
print(min(k - 1, n - k) + 6 + (n - 2) * 3)


t = list(map(int, input().split()))
pos = t[1]
len_t = t[0]
print(3 * len_t + min(abs(len_t - pos + 1), pos) - 1)


temp = map(int, input().split(' '))
(x, y) = temp
if y == 1 or x == y:
	t = 5 + (x - 2) * 2 + x - 1
elif x - y >= y:
	t = 5 + (x - 2) * 2 + (y - 1) * 2 + x - y
elif x - y < y:
	t = 5 + (x - 2) * 2 + y + 1 + (x - y - 1) * 2
print(t)


def mp():
	return map(int, input().split())
(n, k) = mp()
ans = min(k - 1, n - k) + n - 1
ans += 2 * (n - 1)
ans += 3
print(ans)


(n, k) = [int(x) for x in input().split()]
summ = 0
if n - k < k:
	summ += (n - k + 1) * 3 - 1
	summ += n - k + 2
	summ += (k - 1) * 3 - 1
else:
	summ += (k + 1) * 3 - 1
	summ += k + 2
	summ += (n - k - 1) * 3 - 2
print(summ)


(n, k) = [int(i) for i in input().split()]
if k == 1 or k == n:
	print(3 * n)
else:
	print(3 * n + min(n - k, k - 1))


(n, k) = [int(s) for s in input().split()]
x = 2
b = min(k - 1, n - k)
x = x + 3 * b
x = x + b + 1
x = x + max(k - 1, n - k) * 3
print(x)


(n, k) = map(int, input().split())
c = 2 * n + 1
if k <= n // 2:
	c += n + k - 2
else:
	c += 2 * n - k - 1
print(c)


(n, p) = map(int, input().split())
print(3 * n + min(p - 1, n - p))


(n, k) = (int(x) for x in input().split())
ans1 = 2 * (k - 1) + (n - k) + n + (n + 1)
ans2 = k - 1 + 2 * (n - k) + n + (n + 1)
print(min(ans1, ans2))


(holes, position) = list(map(int, input().split()))
moves = holes * 2 + 1
if position <= holes // 2:
	moves += position - 1 + (holes - 1)
else:
	moves += holes - position + (holes - 1)
print(moves)


l = list(map(int, input().split()))
print(3 * l[0] + min(l[1] - 1, l[0] - l[1]))


(n, k) = map(int, input().split())
c = 2 * n + 1
c += min(abs(1 - k), abs(k - n)) * 2 + max(abs(1 - k), abs(k - n))
print(c)


(n, k) = map(int, input().split())
f = 3 * n
if n != k and k != 1:
	f = min(k - 1, n - k) + f
print(f)


(n, k) = map(int, input().split())
ans = 0
if n == 2:
	ans += 6
elif k == 1 or k == n:
	ans += 6 + 3 * (n - 2)
elif k <= n // 2:
	ans += 3 * (n - k)
	ans += 2 + 3 + (k - 2) * 2 + 2 * (k - 1)
else:
	ans += 3 * (k - 1)
	ans += 2 + 3 + (n - k - 1) * 2 + 2 * (n - k)
print(ans)


import sys
from functools import reduce
(n, k) = map(int, sys.stdin.readline().split())
turns = 0
steps = (k - 1 if k <= n / 2 else n - k) + (n - 1)
turns += steps
turns += 2 * (n - 1) + 3
print(turns)


from math import *
(N, K) = map(int, input().split())
print(2 * N + 1 + (N - 1) + min(K - 1, N - K))


(n, k) = map(int, input().split())
k = k - 1
l1 = [0 for i in range(n)]
l2 = [1 for i in range(n)]
count = -1
if n - k > k:
	left = 1
else:
	left = 0
while 0 in l1:
	if l1[k] == 0:
		count += 1
		if 0 in l2:
			l2[l2.index(0)] = l2[k]
		else:
			l2[k - 1] += 1
		count += l2[k]
		l1[k] = 1
		count += 1
		l2[k] = 0
		if k > 0 and left == 1:
			k = k - 1
		elif k == 0:
			k = k + 1
			left = 0
		elif k == n - 1:
			k = k - 1
			left = 1
		else:
			k = k + 1
	else:
		count += 1
		if left == 1:
			k = k - 1
		else:
			k = k + 1
print(count)


(n, k) = [int(x) for x in input().split()]
moving = min(k - 1, n - k) + n - 1
lifting = n
throwing = 3 + n - 2
print(moving + lifting + throwing)


import math
(n, p) = [int(x) for x in input().split()]
res = 2 * n + 1
res = res + min(p - 1, n - p) + n - 1
print(res)


[t, k] = list(map(int, input().split()))
if k == 1 or k == t:
	print(3 * t)
else:
	sum = 6 + (t - 2) * 3
	m = min(t - k, k - 1)
	sum += m
	print(sum)


def getIntList(lst):
	assert type(lst) is list
	rep = []
	for i in lst:
		rep.append(int(i))
	return rep
(n, k) = getIntList(input().split(' '))
ans = 3 * n
if n - k > k - 1:
	ans += k - 1
else:
	ans += n - k
print(ans)


(n, k) = list(map(int, input().split()))
if k > n // 2:
	k = n + 1 - k
print(2 * (k - 1) + 1 + k + 2 + 2 * (n - k - 1) + n)


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def ceil(a, b):
	return (a + b - 1) // b
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
test = 0

def solve():
	(n, k) = mi()
	ans = (n - k) * 3 + (k - 1) * 3 + 1 + min(k - 1, n - k) + 2
	print(ans)
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = sys.stdin.readline
t = 1
if test:
	t = ii()
for _ in range(t):
	solve()


(n, k) = list(map(int, input().rstrip().split(' ')))
m = 0
if k <= n / 2:
	m += k * 3
	if k != n:
		m += k - 1
		m += (n - k) * 3
else:
	m += (n - k + 1) * 3
	m += n - k
	m += (k - 1) * 3
print(m)


(n, m) = map(int, input().split())
s = 3
if m - 1 <= n - m:
	s += (m - 1) * 2 + 2 * (m - 1)
	s += (n - m) * 2 + n - m
else:
	s += (n - m) * 2 + 2 * (n - m)
	s += (m - 1) * 2 + m - 1
print(s)


import math
from collections import defaultdict as dd
(n, k) = [int(i) for i in input().split(' ')]
print(3 * n + min(n - k, k - 1))


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict
import math

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
(n, k) = listIn()
arr = [0] * n
arr[0] = 2 + 4 + 3 * (n - 2)
if n % 2 == 0:
	mid = n // 2
else:
	mid = n // 2 + 1
for i in range(1, mid):
	arr[i] = arr[i - 1] + 1
for i in range(mid, n):
	arr[i] = arr[n - i - 1]
print(arr[k - 1])


(n, k) = map(int, input().split())
k -= 1
sd = min(k, n - k - 1)
print(sd + n * 3)


def main():
	(n, k) = [int(v) for v in input().split()]
	state = [1 for i in range(n)]
	k = k - 1
	v = min(k, n - k - 1)
	res = (v - 1) * 3 + v + max(k, n - k - 1) * 3 + 6
	print(res)
main()