#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

constexpr int MAXN = 2*1e6 + 100;
int a[MAXN];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int n;
    cin >> n;

    for (int i = 0; i < n; i++)
        cin >> a[i];

    int ans = 0;
    int i, j, MAX;
    for (i = 0; i < n-1; i++)
    {
        MAX = a[i];
        for (j = i+1; j < n; j++)
        {
            MAX = max(MAX, a[j]);

            if (a[j] >= MAX || a[i] >= MAX)
                ans++;
        }
    }

    cout << ans << endl;

    return 0;
}
