while 1:
  n = input()
  if n==0: break
  x = [int(raw_input()) for _ in [0]*n]
  c = 0
  for i in range(n):
    for j in range(i+1,n)[::-1]:
      if x[j] < x[j-1]:
        x[j], x[j-1] = x[j-1], x[j]
        c += 1
  print c