#include <bits/stdc++.h>
using namespace std;
bool compare_by_b(pair<string, int64_t> a, pair<string, int64_t> b) {
  if (a.second != b.second)
    return a.second < b.second;
  else
    return a.first < b.first;
}
bool my_compare(pair<string, int64_t> a, pair<string, int64_t> b) {
  if (a.first != b.first) return a.first < b.first;
  if (a.second != b.second)
    return a.second > b.second;
  else
    return true;
}
int64_t factorial(int64_t n) {
  int64_t x = 1;
  for (int64_t i = 1; i <= n; i++) x *= i;
  return x;
}
int64_t gcd(int64_t a, int64_t b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
int64_t lcm(int64_t a, int64_t b) { return a / gcd(a, b) * b; }
void f(int64_t rest, string s) {
  if (rest == 0) {
    cout << s << endl;
  } else {
    for (char c = 'a'; c <= 'c'; c++) {
      f(rest - 1, s + c);
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64_t n;
  cin >> n;
  vector<int64_t> a;
  for (int64_t i = 0; i < n; i++) {
    int64_t k;
    cin >> k;
    if (k == i + 1) a.push_back(k);
  }
  int64_t sum = 0;
  for (int64_t i = 0; i < a.size(); i++) {
    sum += a[i + 1] - a[i];
    i++;
  }
  cout << sum << endl;
  return 0;
}
