N, X = gets.chomp.split(" ").map(&:to_i)

def calc(n, d)
  return 1 if n == 0
  return 0 if d == 1
  wk = 2 ** (n+1) - 1
  return 2**n if d == wk
  return 2**(n+1) - 1 if d == 2 * wk - 1
  if wk < d then
    2**n + calc(n-1, d-wk)
  else
    calc(n-1, d-1)
  end
end

puts calc(N, X)
