#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int p[n + 1];
  for (long long int i = 1; i <= n; i++) {
    cin >> p[i];
  }
  long long int s = 0;
  long long int ans = 0;
  bool is_in = false;
  for (long long int i = 1; i <= n; i++) {
    if (p[i] == i) {
      if (!is_in) {
        s = i;
        is_in = true;
      } else {
        ans += i - s;
        is_in = false;
      }
    }
  }
  cout << ans << endl;
}
