# coding: utf-8 # Your code here! N = int(input()) a = list(map(int,input().split())) #print(a) m = len(a) orderCount = 1 # 順番に並んでる個数 for i in range(2,m+1)[::-1]: if a.index(i-1) > a.index(i): break else: orderCount += 1 print(m-orderCount)