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