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

@length_map = {}

def b_length n
  if n == 0
    1
  else
    @length_map[n] ||= ( 3 + (2 * b_length(n - 1)) )
  end
end

def answer n , x
  if n == 0
    if x >= 1
      1
    else
      0
    end
  else
    if x == 1
      0
    elsif (1 + b_length(n-1)) >= x
      answer(n - 1, x - 1)
    elsif (2 + b_length(n-1)) == x
      1 + answer(n - 1, x - 2)
    elsif (2 + (2 * b_length(n-1))) >= x
      1 + answer(n - 1, b_length(n-1)) + answer(n - 1, x - 2 - b_length(n-1))
    else
      1 + (2 * answer(n - 1, b_length(n-1)))
    end
  end
end
puts(answer n, x) 
