#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> v(n);
map<int, int> cl, cr;
o_set<pair<int, int>> l, r;
for (auto &x : v)
{
cin >> x;
r.insert({x, INT_MAX});
cr[x]++;
}
int ans = 0;
for (int i = 0; i < n; i++)
{
int x = v[i];
// left a chuto
int chuto = l.order_of_key({x, 0});
chuto += cl[x];
cl[x]++;
l.insert({x, INT_MAX});
int f = 0;
if (chuto >= x)
{
ans++;
f = 1;
// continue;
}
cr[x]--;
int boro = cr[x];
boro += (n - i - 1 - cr[x]) - (r.order_of_key({x, 0}));
if (cr[x] == 0)
r.erase({x, INT_MAX});
if (boro >= x and !f)
{
ans++;
}
}
cout << ans << '\n';
return 0;
}