N = int(input()); a = [int(i) for i in input().split()] maxIndex = a.index(N) i = maxIndex - 1 b = 0 while i >= 0: if a[i] == N - b - 1: b += 1 i -= 1 ans = (N - maxIndex - 1) + (maxIndex - b) print (ans)