n = int(input()) a = list(map(int, input().split())) for ai in a[::-1]: if ai == n: n -= 1 print(n)