#include using namespace std; #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) #define rrep(i,n) for (int i=(n)-1;i>=0;i--) #define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--) #define all(a) (a).begin(),(a).end() typedef long long ll; typedef pair P; const int MAX_N = 100000; vector input(){ string line; getline(cin, line); stringstream ss(line); vector in; int x; while (ss >> x) { in.emplace_back(x); } return in; } signed main() { std::ios::sync_with_stdio(false); std::cin.tie(0); vector in = input(); assert(in.size() == 1); int N = in[0]; assert(1 <= N && N <= MAX_N); vector a = input(); assert(a.size() == N); set s; rep(i, N) { assert(1 <= a[i] && a[i] <= N); assert(s.count(a[i]) == 0); s.insert(a[i]); } int buttom = N; rrep(i, N) { if (a[i] == buttom) buttom--; } cout << buttom << endl; }