n = int(input()) a = list(map(int,input().split())) s = 0 ma = n for i in range(n - 1,-1,-1): if a[i] == ma: s += 1 ma -= 1 print(n - s)