#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n - 1);
  int sum = 0;
  for (int i = 0; i < (int)(n); i++) {
    sum += b[a[i]];
    if (a[i + 1] == a[i] + 1) {
      sum += c[i];
    }
  }
  cout << sum << endl;
}
