#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> match;
  int tmp;
  for (int i = 1; i <= N; ++i) {
    cin >> tmp;
    if (i == tmp) match.push_back(tmp);
  }
  int ans = 0;
  int matchCount = match.size();
  for (int i = 1; i < matchCount; i += 2) {
    int distance = match[i] - match[i - 1];
    ans += distance;
  }
  if (matchCount % 2) {
    int last = matchCount - 1;
    int distance = match[last] - match[last - 1];
    ans += distance;
  }
  cout << ans << endl;
  return 0;
}
