n,x=gets.split.map(&:to_i)

m = 1
p = 1
LMAP = [1]
PMAP = [1]
n.times do
  m = 3 + m * 2
  p = 1 + p * 2
  LMAP << m
  PMAP << p
end

def count(l, a)
  return 0 if a == 0

  if a < LMAP[l] / 2
    count(l-1,a-1)
  elsif a == LMAP[l] / 2 + 1
    1 + PMAP[l-1]
  elsif a == LMAP[l] / 2
    PMAP[l-1]
  else # a > lmap[l] / 2
    PMAP[l-1] + 1 + count(l-1,a-(LMAP[l]/2+1))
  end
end

p count(n,x)