n = int(input()) a = list(map(int,input().split())) s = 0 if a[n - 1] == n: s += 1; t = a[n - 1] f = True for i in range(n - 2,-1,-1): if a[i] == 1: f = True if a[i] + 1 == t: s += 1 t = a[i] f = False if f: s += 1 print(n - s)