f::Integer->[(Integer,Integer)]
f 0=[(1,0)]
f n=let es=f (n-1)
        (p,b)=head es
    in (p*2+1,b*2+2):es

f2::Integer->[(Integer,Integer)]->Integer
f2 x _
    |x<=0=0
f2 _ ((1,0):[])=1
f2 x ((p,b):(p2,b2):xs)
      |x>=p+b=p
      |x>p2+b2+2=(p2+1) + (f2 (x-2-b2-p2) ((p2,b2):xs))
      |x==p2+b2+2=p2+1
      |otherwise=f2 (x-1) ((p2,b2):xs)

main = do
       e<-getLine
       let (n:k:[])=map read (words e)::[Integer]
           xs=f n
       putStrLn $ show $ f2 k xs