n = int(input()) *a, = map(int,input().split()) ans = 0 for i in a[::-1]: if i != n: ans += 1 else: n -= 1 print(ans)