n, x = gets.chomp.split(' ').map(&:to_i)
$arr_p = Array.new(n + 1, 0)
$arr_n = Array.new(n + 1, 0)
$arr_p[0] = 1
$arr_n[0] = 1

(1..n).each do |i|
  $arr_p[i] = $arr_p[i - 1] * 2 + 1
  $arr_n[i] = $arr_n[i - 1] * 2 + 3
end

def func(n, x)
  if n == 0
    return 1
  elsif x == 1
    return 0
  elsif $arr_n[n - 1] + 1 > x
    return func(n - 1, x - 1)
  elsif $arr_n[n - 1] + 1 == x
    return $arr_p[n - 1]
  elsif $arr_n[n - 1] + 2 == x
    return $arr_p[n - 1] + 1
  else
    return func(n - 1, [x - $arr_n[n - 1] - 2, $arr_n[n - 1]].min) + $arr_p[n - 1] + 1
  end
end

puts func(n, x)