def num_patty(n, x)
  np = Array.new(n + 1)
  np[0] = 1
  (1..n).each do |i|
    np[i] = 2 * np[i - 1] + 1
  end

  w = Array.new(n + 1)
  w[0] = 1
  (1..n).each do |i|
    w[i] = 2 * w[i - 1] + 3
  end

  memo = {}

  num_p = -> n, x {
    if n == 0
      return x >= 1 ? 1 : 0
    end

    memo[[n, x]] ||=
      if x <= 1
        0
      elsif x <= w[n - 1] + 1
        num_p.call(n - 1, x - 1)
      elsif x <= w[n - 1] + 2
        num_p.call(n - 1, x - 1) + 1
      elsif x <= 2 * w[n - 1] + 2
        np[n - 1] + 1 + num_p.call(n - 1, x - w[n - 1] - 2)
      else
        np[n]
      end
  }

  num_p.call(n, x)
end

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