#include "bits/stdc++.h" using namespace std; #define print(x) cout< PI; typedef pair V; typedef vector VE; const ll mod = 100000000000; int main() { int n; cin >> n; int m=n; VE a(n); REP(i,n)cin>>a[i]; REP(i,n){ //print(a[n-i]); if(a[n-i]==m){ //print("-") m--; } } print(m-1); }