#include "bits/stdc++.h" using namespace std; #define int long long #define PB push_back #define PPB pop_back typedef pair pii; typedef pair pdd; static const int INF = 1LL << 61; int dp[100005], n, a[100005]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = n - 1; 0 <= i; --i) cin >> a[i]; int ans = n; for (int i = 0; i < n; ++i) if (a[i] == ans) ans--; cout << ans << endl; }