#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, a[N], ans = 0;
void solve(int l, int r) {
  if (l < r) {
    int mid = (l + r) >> 1;
    solve(l, mid);
    solve(mid + 1, r);
    if (a[mid] == mid || a[mid + 1] == mid + 1) {
      ans++;
      swap(a[mid], a[mid + 1]);
    }
  } else
    return;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  solve(1, n);
  cout << ans << endl;
  return 0;
}
