def dfs(n, x)
  return 0 unless 0<=x && x<=S[n]
  return dfs(n-1, x-1) if x-1<=S[n-1]
  x -= 1 + S[n-1]
  P[n-1] + 1 + (x==1 ? 0 : dfs(n-1, x-1))
end

N,X=gets.split.map(&:to_i)

S=*P=Array.new(N+1){0}
P[0]=S[0]=1
N.times do |n|
  P[n+1] += 1+2*P[n]
  S[n+1] += 3+2*S[n]
end

p dfs(N, X)
