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

arr = []
i = n + 1
y = x - 1
p = 2**i - 2

loop do
  i = i-1
  case
  when y < p
    arr << [:left, i]
    p = p - 2**i + 1
  when y > p
    arr << [:right, i]
    p = p + 2**i - 1
  when y == p
    arr << [:middle, i]
    break
  end
  break if i == 0
end

r = 0

arr.each do |v|
  case v[0]
  when :right, :middle
    r = r + 2**(v[1])
  end
end

puts r
