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

BARGER_COUNT_TABLE =
  (1..N).reduce({ 0 => 1 }) do |acc, n|
    m = acc[n - 1]
    acc[n] = m * 2 + 3
    acc
  end

PATTIE_MAX_COUNT_TABLE =
  (1..N).reduce({ 0 => 1 }) do |acc, n|
    m = acc[n - 1]
    acc[n] = m * 2 + 1
    acc
  end

def patti_eat_count(n, x)
  count = BARGER_COUNT_TABLE[n]
  center = (count / 2) + 1
  if n == 0
    PATTIE_MAX_COUNT_TABLE[0]
  elsif x <= n
    0
  elsif x < center
    patti_eat_count(n - 1, x - 1)
  elsif x == center
    PATTIE_MAX_COUNT_TABLE[n - 1] + 1
  elsif x < count - n
    patti_eat_count(n, center) + patti_eat_count(n - 1, x - center)
  else
    PATTIE_MAX_COUNT_TABLE[n]
  end
end
puts patti_eat_count(N, X)
