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

@layer = [1]
@meat = [1]
1.upto(N) do |i|
  @layer[i] = @layer[i - 1] * 2 + 3
  @meat[i] = @meat[i - 1] * 2 + 1
end

def search(n, x)
  return 0 if x <= 0
  return 1 if n == 0 && x == 1
  if x <= @layer[n - 1] + 1
    return search(n - 1, x - 1)
  elsif x == @layer[n - 1] + 2
    return @meat[n - 1] + 1
  elsif x <= @layer[n - 1] * 2 + 2
    return @meat[n - 1] + 1 + search(n - 1, x - @layer[n - 1] - 2)
  else
    return @meat[n - 1] * 2 + 1
  end
end

puts search(N, X)