#include <bits/stdc++.h>
using namespace std;
vector<long int> ar;
int main() {
  long int n, i, ans = 0, a;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a;
    if (a == i) {
      ar.push_back(i);
    }
  }
  for (i = 0; i < ar.size() - 1; i += 2) {
    if (i < ar.size() - 1) {
      ans += ar[i + 1] - ar[i];
    }
  }
  if (ar.size() % 2) {
    ans += ar[ar.size() - 1] - ar[ar.size() - 2];
  }
  cout << ans;
  return 0;
}
