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

class CalcBurger
  def initialize(i)
    @memo = {0 => 1 }
    @total = {
      0 => 1,
      1 => 3,
      2 => 7,
    }
    i.times do  |j|
      next if j == 0 
      @memo[j]  = 2*@memo[j-1] + 3
      @total[j] = 2*@total[j-1] + 1
    end
  end

  def execute(n, x)
    if x == 1 
      0
    elsif x <= @memo[n-1] + 1
      return execute(n-1, x-1)
    else
      return @total[n-1] + 1 + execute(n-1, x - 2 - @memo[n-1])
    end
  end
end
puts CalcBurger.new(n).execute(n, x)

