N = int(input()) P = list(map(int, input().split())) if N == 1: print(0) exit() total = 0 for i, p in enumerate(P): if p != N: total += i+1 else: total -= i+1 if total < 0: print(0) else: print(total)