#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, r1 = 0, r2 = 0, res = 0, rr = 0;
  cin >> n;
  int a[n + 10], b[n + 10], c[n + 10];
  map<int, int> m;
  int dp[n + 10];
  for (i = 0; i <= n + 2; i++) dp[i] = 0;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  if (a[1] == 1 && a[n] == n) {
    rr = 1;
    swap(a[1], a[n]);
    swap(b[1], b[n]);
    swap(c[1], c[n]);
  }
  for (i = 1; i <= n; i++) {
    if (b[i] == i) {
      r1++;
      swap(b[i], b[i + 1]);
    }
    dp[i] = r1;
  }
  res = r1;
  for (i = n; i > 0; i--) {
    if (a[i] == i) {
      r2++;
      swap(a[i], a[i - 1]);
      res = min(res, dp[max(0, i - 2)] + r2);
    } else
      res = min(res, dp[i - 1] + r2);
    dp[i] = r2;
  }
  r1 = 0;
  for (i = 1; i <= n; i++) {
    if (c[i] == i) {
      r1++;
      swap(c[i], c[i + 1]);
      res = min(res, dp[i + 2] + r1);
    } else
      res = min(res, dp[i + 1] + r1);
  }
  cout << res + rr;
  return 0;
}
