#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int maxn = 1e5 + 5;
int a[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < (n); ++i) cin >> a[i];
  if (n < 3) return !printf("0\n");
  int ans = inf;
  int d[3] = {0, 1, -1};
  for (int i = 0; i < (3); ++i)
    for (int j = 0; j < (3); ++j) {
      int x = d[i], y = d[j];
      a[0] += x, a[1] += y;
      int diff = a[1] - a[0], cnt = abs(x) + abs(y);
      bool ok = true;
      for (int k = 0; k < (n); ++k) {
        int t = abs(a[k] - (a[0] + k * diff));
        if (t > 1) ok = false;
        cnt += t;
      }
      if (ok) ans = min(ans, cnt);
      a[0] -= x, a[1] -= y;
    }
  cout << (ans == inf ? -1 : ans) << endl;
  return 0;
}
