#n = gets.chomp.to_i
debug = false
n,x = gets.chomp.split().map(&:to_i)

i = 1
all = [1]
pati = [1]

n.times do
  all.push(all.last * 2 + 3)
  pati.push(1 + pati.last * 2)
end

all.reverse!
pati.reverse!
p ['all', all] if debug
p ['pati', pati] if debug

ans = 0
all.size.times do |i|
  print [i, '', x, all[i], '', ans] if debug
  if all[i] == 1
    ans ++ 1
    break
  elsif all[i] == 5 && x <= 5
    ans += [[x-1, 0].max, 3].min
    break
  end

  if x == 0
    break
  elsif x == 1
    ans += 1 if all[i] < 5
    break
  elsif x < 1 + all[i]
    x-=1
  elsif x == 1 + all[i]
    x = 0
    ans += pati[i] + 1
  elsif x == 1 + all[i] + 1
    x = 0
    ans += pati[i] + 1
  elsif x < all[i]*2 + 2
    x -= (all[i] + 2)
    ans += pati[i] + 1
  elsif all[i]*2 + 2 == x
    x = 0
    ans += pati[i] * 2 + 1
  elsif all[i]*2 + 3 == x
    x = 0
    ans += pati[i] * 2 + 1
  else
    raise RuntimeError
  end
  p ['->', x, ans] if debug
end

# puts pati.inject(:+)
puts ans
