#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7;
int n, a[N], f[N][21], pos[N], nxt[N], tmp[N], ans;
int query(int l, int r) {
  int k = log2(r - l + 1);
  return max(f[l][k], f[r - (1 << k) + 1][k]);
}
int main() {
  scanf("%d", &n);
  memset(pos, 0x3f, sizeof(pos));
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]), f[i][0] = a[i];
    pos[tmp[a[i]]] = i;
    tmp[a[i]] = i;
  }
  nxt[n] = n;
  for (int i = n - 1; i >= 1; --i) nxt[i] = min(nxt[i + 1], pos[i] - 1);
  for (int j = 1; j <= 20; ++j)
    for (int i = 1; i + (1 << j) - 1 <= n; ++i)
      f[i][j] = max(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= nxt[i];) {
      int A = query(i, j);
      if (A <= j - i + 1)
        ans++, j++;
      else
        j = i + A - 1;
    }
  }
  cout << ans << "\n";
  return 0;
}
