burger :: Int -> Char
burger 0 = 'P'
burger x = 'B' ++ burger (x-1) y ++ 'P' ++ burger (x-1) y ++ 'B'

count :: String -> Int -> Int -> Int
count str a 0 = a
count str a b =
	if head str == 'P' then count (tail str) (a+1) (b-1)
		else count (tail str) a (b-1)

main :: IO()
main = do
	N <- getChar
	X <- getChar
	str1 <- buger (read N :: Int)
	str2 = reverse str1
	a = count str2 0 (read X :: Int)
	putStrLn a
