#include <bits/stdc++.h>
using namespace std;
long long keta(long long x) {
  for (long long i = 0; i < 30; i++) {
    if (x < 10) {
      return i + 1;
    }
    x = x / 10;
  }
}
long long gcd(long long x, long long y) {
  long long aa = x, bb = y;
  for (long long i = 0; i < 1000; i++) {
    aa = aa % bb;
    if (aa == 0) {
      return bb;
    }
    bb = bb % aa;
    if (bb == 0) {
      return aa;
    }
  }
}
long long lcm(long long x, long long y) {
  long long aa = x, bb = y;
  for (long long i = 0; i < 1000; i++) {
    aa = aa % bb;
    if (aa == 0) {
      return x / bb * y;
    }
    bb = bb % aa;
    if (bb == 0) {
      return x / aa * y;
    }
  }
}
char mem[214514];
long long t[214514], second[214514];
long long a[214514], b[214514];
signed main() {
  long long n;
  cin >> n;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (i + 1 == a[i]) {
      b[sum] = a[i];
      sum++;
    }
  }
  long long ans = 0;
  if (sum % 2 == 1) {
    t[0] = b[1] - b[0];
    second[0] = b[sum - 1] - b[sum - 2];
    for (long long i = 1; i < (sum + 1) / 2; i++) {
      t[i] = t[i - 1] + b[i * 2 + 1] - b[i * 2];
      second[i] = second[i - 1] + b[sum - i * 2 + 1] - b[sum - i * 2];
    }
    for (long long i = 0; i < (sum + 1) / 2; i++) {
      ans = min(ans, t[i] + second[(sum - 1) / 2 - i]);
    }
  } else {
    for (long long i = 0; i < sum; i += 2) {
      ans += b[i + 1] - b[i];
    }
  }
  cout << abs(ans) << endl;
}
