#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long to;
  long long cost;
};
int solve() {
  long long n;
  cin >> n;
  vector<long long> p(n);
  for (long long i = 0; i < n; i++) {
    cin >> p[i];
  }
  long long ans = 0;
  long long r, l;
  while (r < n) {
    if (p[l] == l + 1 && p[r] == r + 1 && r != l) {
      ans += r - l;
      l = r + 1;
      r++;
      continue;
    }
    if (p[r] == r + 1) {
      l = r;
    }
    r++;
  }
  cout << ans << endl;
  return 0;
}
int main(void) {
  solve();
  return 0;
}
