#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000001;
const int max_n = 100005;
int arr[max_n + 1];
int state[max_n + 1];
int main(void) {
  int n;
  int i;
  int nb_perm = 0;
  int nb_wrong = 0;
  scanf("%d\n", &n);
  int arr[n + 1];
  for (i = 0; i < n; ++i) {
    scanf("%d", &arr[i]);
    if (arr[i] == (i + 1)) {
      state[i] = 1;
      ++nb_wrong;
    }
  }
  for (i = 0; i < n; ++i) {
    if (state[i] == 1) {
      if (nb_wrong == 1) {
        ++nb_perm;
        break;
      }
      int prev, next;
      bool found = false;
      int min_dist = 0;
      int dist_prev, dist_next;
      prev = i - 1;
      next = i + 1;
      while (!found && (prev >= 0 || next < n)) {
        dist_prev = dist_next = 0;
        if (prev >= 0 && (state[prev] == 1 || state[prev] == 2)) {
          dist_prev = i - prev;
          found = true;
        }
        if (next < n && (state[next] == 1 || state[next] == 2)) {
          dist_next = next - i;
          found = true;
        }
        if (dist_prev != 0 && dist_next == 0) {
          if (state[prev] == 1) --nb_wrong;
          state[prev] = 2;
          min_dist = dist_prev;
        } else if (dist_next != 0 && dist_prev == 0) {
          if (state[next] == 1) --nb_wrong;
          state[next] = 2;
          min_dist = dist_next;
        } else if (dist_prev != 0 && dist_next != 0) {
          if (state[prev] == 1) {
            --nb_wrong;
            state[prev] = 2;
            min_dist = dist_prev;
          } else if (state[next] == 1) {
            --nb_wrong;
            state[next] = 2;
            min_dist = dist_next;
          }
        }
        --prev;
        ++next;
      }
      if (min_dist != 0) {
        state[i] = 2;
        nb_perm += min_dist;
        --nb_wrong;
      }
    }
  }
  printf("%d\n", nb_perm);
  return 0;
}
