#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int n, p[110000], now, l, r, sum, lt, rt, t;
int main() {
  n = read();
  for (int i = 1; i <= n; i++) p[i] = read();
  now = 1;
  while (now <= n) {
    while (now + 1 <= n + 1 && now != p[now]) now++;
    if (p[now] == now) {
      l = now;
      r = now;
      while (l - 1 >= 1 && (p[l - 1] == p[now] || p[now] == l - 1)) {
        l--;
      }
      while (r + 1 <= n && (p[r + 1] == p[now] || p[now] == r + 1)) {
        r++;
      }
      l--;
      r++;
      lt = now - l;
      rt = r - now;
      if (l >= 1 && lt < rt) {
        sum += lt;
        t = p[now];
        p[now] = p[l];
        p[l] = t;
      } else if (r <= n) {
        sum += rt;
        t = p[now];
        p[now] = p[r];
        p[r] = t;
      }
    }
  }
  printf("%d\n", sum);
  return 0;
}
