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

LAYER = Hash.new do |h, i|
  h[i] = h[i - 1] * 2 + 3
end
LAYER[0] = 1

def calc(level, i)
  return 1 if level == 0
  full = LAYER[level]
  center = full / 2 + 1
  if i <= 1
    0
  elsif i < center
    calc(level - 1, i - 1)
  elsif i == center 
    calc(level - 1, center - 2) + 1
  elsif i < full
    calc(level - 1, center - 2) + 1 + calc(level - 1, i - center) 
  else  
    calc(level - 1, center - 2) * 2 + 1
  end
end

puts calc(N, X)