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

HEIGHTS = [1]
PATES = [1]
1.upto(N) do |l|
  HEIGHTS[l] = HEIGHTS[l - 1] * 2 + 3
  PATES[l] = PATES[l - 1] * 2 + 1
end
# p HEIGHTS, PATES

def f(l, x)
  if l == 0
    x > 0 ? 1 : 0
  elsif x <= HEIGHTS[l - 1] + 1 # バーガー＋前レベルの階層
    f(l - 1, x - 1)
  else # バーガー＋前のレベル＋真ん中パティ＋前のレベルの階層
    PATES[l - 1] + 1 + f(l - 1, x - HEIGHTS[l - 1] - 2)
  end
end

puts f(N, X)