#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, i;
  cin >> n;
  int a[n + 1], x, ans = 0, k = 0;
  for (i = 1; i <= n; i++) {
    cin >> x;
    if (x == i) a[k++] = i;
  }
  for (i = 0; i < k - 1; i += 2) ans += (a[i + 1] - a[i]);
  cout << ans;
  return 0;
}
