#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <numeric>
#include <cassert>
using namespace std;
#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(...) DBG2::cprint(#__VA_ARGS__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif
#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
using llong = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using II = pair<int,int>;
class BinaryIndexedTree {
int N;
vector<int> tree;
public:
BinaryIndexedTree(int _N) : N(_N), tree(_N+1) {}
int query(int idx) const {
assert(idx <= N);
int res = 0;
for (int i = idx; i > 0; i -= (i & -i))
res += tree[i];
return res;
}
int query(int L, int R) const {
R = min(R, N);
L = max(L, 1);
return L <= R ? query(R) - query(L-1) : 0;
}
void update(int idx, int val = 1) {
for (int i = idx; i <= N; i += (i & -i))
tree[i] += val;
}
};
int solve(int N, VI A) {
for (int& a : A) a++;
vector<bool> special(N, true);
{
BinaryIndexedTree bit(N + 10);
for (int i = 0; i < N; i++) {
int a = A[i];
bit.update(a);
int cnt = bit.query(a);
if (cnt < a-1)
special[i] = false;
}
}
{
BinaryIndexedTree bit(N + 10);
for (int i = N-1; i >= 0; i--) {
int a = A[i];
bit.update(a);
int cnt = bit.query(a, N+10);
if (cnt < a-1)
special[i] = false;
}
}
int res = count(special.begin(), special.end(), true);
return res;
}
int main(int argc, char* argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
VI A(N);
REP(i, N)
cin >> A[i];
int res = solve(N, A);
cout << res << '\n';
return 0;
}