N,X = gets.split.map(&:to_i)
MEMO = []
def content(n)
  return MEMO[n] unless MEMO[n].nil?
  if n == 0
    [1, 0]
  else
    before = content(n-1)
    value = [before[0]*2 + 1, before[1]*2 + 2]
    MEMO[n] = value
    value
  end
end

# P
# B P P P B
# B BPPPB P BPPPB B
# B BBPPPBPBPPPBB P BBPPPBPBPPPBB B
# returns number of P
def burger(n, x)
  burger_content = content(n)
  # puts "burger(#{n}, #{x}), #{burger_content.to_s}"
  burger_size = burger_content.inject(:+)
  half = (burger_size+1) / 2
  if x <= 1
    0
  elsif x < half
    burger(n-1, x-1)
  elsif x == half
    burger(n-1, x-2) + 1
  elsif x < burger_size
    burger(n-1, half-2) + burger(n-1, x-half) + 1
  elsif x == burger_size
    burger_content[0]
  else
    puts "Failed burger(#{n}, #{x})"
  end
end

puts burger(N, X)
