#include <bits/stdc++.h>
const signed long long int MAX_SLLI = 0x7FFFFFFFFFFFFFFF;
const signed long long int MIN_SLLI = 0x8000000000000000;
const unsigned long long int MAX_ULLI = 0xFFFFFFFFFFFFFFFF;
const unsigned long long int MIN_ULLI = 0x0000000000000000;
int main() {
  long N;
  std::cin >> N;
  std::vector<long> p(N);
  for (long n = 0; n < N; ++n) {
    std::cin >> p[n];
  }
  std::vector<long> q(N);
  for (long n = 0; n < N; ++n) {
    q[n] = p[n] - (n + 1);
  }
  unsigned c1 = 0;
  std::vector<long> q1(q);
  for (long n = 0; n < N - 1; ++n) {
    if (q1[n] == 0) {
      long r = q1[n];
      q1[n] = q1[n + 1] + 1;
      q1[n + 1] = r - 1;
      ++c1;
    }
  }
  unsigned c2 = 0;
  std::vector<long> q2(q);
  for (long n = N - 1; n > 0; --n) {
    if (q2[n] == 0) {
      long r = q2[n];
      q2[n] = q2[n - 1] - 1;
      q2[n - 1] = r + 1;
      ++c2;
    }
  }
  if (std::find(q1.begin(), q1.end(), 0) != q1.end()) {
    c1 = N << 1;
  }
  if (std::find(q2.begin(), q2.end(), 0) != q2.end()) {
    c2 = N << 1;
  }
  std::cout << std::min(c1, c2) << std::endl;
  return 0;
}
