#include<iostream>
using namespace std;

int A[100001], n;
int jShu;

int main(){
	cin>>n;
	for(int i=0; i<n; i++) cin>>A[i];
	int Shu = n;
	for(int j=n-1; j>=0; j--){
		if(A[j] == Shu){
			Shu--;
			jShu++;
		}
	}
	cout<<n-jShu<<endl;
	return 0;
}
