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

# layers(l) = 'B' + layers(l-1) + 'P' + layers(l-1) + 'B'

class Burger
  def initialize(n)
    @layers = [1]
    @number_of_patties = [1]

    n.times do |i|
      @layers << 2 * @layers[i] + 3
      @number_of_patties << 2 * @number_of_patties[i] + 1
    end
  end

  def solve(n, x)
    if n == 0
      if x == 0
        return 0
      else
        return 1
      end
    end

    if x == 1
      return 0
    elsif x <= @layers[n-1] + 1
      return solve(n-1, x - 1)
    elsif x == @layers[n-1] + 2
      return @number_of_patties[n-1] + 1
    elsif x < 2*@layers[n-1] + 2
      return @number_of_patties[n-1] + 1 + solve(n - 1, x - 1 - 1 - @layers[n - 1])
    elsif x == 2*@layers[n-1] + 2
      return 2 * @number_of_patties[n-1] + 1
    end
  end
end

burger = Burger.new(n)
p burger.solve(n, x)
