class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)

  def initialize
    @n, @k = gets.to_s.split.map { |v| v.to_i }
  end

  def solve
    eat(n, k)
  end

  def eat(n, k)
    x = length(n)
    case k
    when 0; 0
    when x; meat(n)
    when x + 1; meat(n) + 1
    when ->k { k < x }; eat(n - 1, k - 1)
    when ->k { k > x + 1 }; meat(n) + 1 + eat(n, k - x - 1)
    end
  end

  def show(ans)
    puts ans
  end

  def length(i); 2 ** (i + 2) - 3; end
  def meat(i); 2 ** (i + 1) - 1; end
end

Problem.new.instance_eval do
  show(solve)
end
