#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair P; constexpr int INF = 1e9; int main(){ int n; cin >> n; vector a(n); rep(i,n) cin >> a[i]; int now = n; for (int i = n-1; i >= 0; i--) { if (a[i] == now) now--; } cout << now << endl; return 0; }