#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,n) for(int i=0; i=b; --i) #define pi M_PI typedef long long ll; typedef vector VI; typedef vector VL; typedef vector VVI; typedef pair P; typedef pair PL; int main(){ int n; cin >> n; VI a(n); REP(i,n) scanf("%d", &a[i]); int x = n; FORR(i,n,1){ if (a[i] == x) x--; } cout << max(x-1,0) << endl; return 0; }