#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;
struct QueueItem {
  long c;
  std::vector<long> v;
  QueueItem(long c, const std::vector<long> &v) : c(c), v(v) {}
};
long search(long N, const std::vector<long> &v) {
  std::queue<QueueItem> q;
  q.emplace(0, v);
  while (!q.empty()) {
    QueueItem item = q.front();
    q.pop();
    auto itr = std::find(item.v.begin(), item.v.end(), 0);
    if (itr == item.v.end()) {
      return item.c;
    }
    long index = std::distance(item.v.begin(), itr);
    if (index >= 1) {
      std::vector<long> u(item.v);
      u[index + 0] = v[index - 1] - 1;
      u[index - 1] = v[index + 0] + 1;
      q.emplace(item.c + 1, u);
    }
    if (index < N - 1) {
      std::vector<long> u(item.v);
      u[index + 0] = v[index + 1] + 1;
      u[index + 1] = v[index + 0] - 1;
      q.emplace(item.c + 1, u);
    }
  }
  return 0;
}
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);
  }
  std::cout << search(N, q) << std::endl;
  return 0;
}
