n = int(input()) a = list(map(int, input().split())) b = sorted(a) out = 0 for i in range(n): now1 = a[n - i - 1] now2 = b[n - i - 1] #print(now1, now2, a.index(now2)) if now1 == now2: pass else: a[a.index(now2)] = now1 a[n - i - 1] = now2 out += 1 print(out)