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

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

S=*P=Array.new(N+2){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)
