#include using namespace std; #define _GLIBCXX_DEBUG #define dump(c) cerr << "> " << #c << " = " << (c) << endl #define all(c) ((c).begin()), ((c).end()) #define rep(i, n) for(int i=0;i<(int)n;i++) #define FOR(i, s, e) for(int (i)=(int)(s);(i)<(int)(e);++(i)) #define inf 0x3f3f3f3f #define infl 0x3f3f3f3f3f3f3f3fLL typedef long long ll; typedef unsigned long long ull; int main() { int N; cin >> N; vector a(N); for (int i = 0; i < N; ++i) cin >> a[i]; int count = 0; int d = N+1; for (int j = N-1; j >= 0; --j) { if (a[j] == d - 1) { count++; d = d - 1; } } cout << N - count << endl; return 0; }