#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
signed main() {
  long long N;
  cin >> N;
  long long p[N + 1];
  long long kyori = 0, ans = 0;
  for (long long i = 1; i <= N; i++) {
    cin >> p[i];
    if (i == p[i] && kyori == 0)
      kyori = i;
    else if (i == p[i] && kyori > 0) {
      kyori = i - kyori;
      ans += kyori;
      kyori = 0;
    }
  }
  cout << ans << endl;
  return 0;
}
