#include <bits/stdc++.h>
using namespace std;
const int sz = 1e5 + 5;
const long long mod = 1e9 + 7;
int main() {
  int n;
  scanf("%d", &n);
  ;
  vector<int> x(n), temp(n);
  for (int i = 0; i < n; i++) scanf("%d", &x[i]);
  if (n <= 2) {
    cout << 0;
    return 0;
  }
  int ans = 1e9;
  for (int i = -1; i <= 1; i++) {
    for (int j = -1; j <= 1; j++) {
      temp = x;
      temp[0] += i, temp[1] += j;
      int tempans = abs(i) + abs(j), dif = temp[0] - temp[1];
      for (int k = 2; k < n; k++) {
        bool yes = 0;
        for (int g = -1; g < 2; g++) {
          if (temp[k - 1] - (temp[k] + g) == dif) {
            temp[k] += g;
            yes = 1;
            tempans += abs(g);
            break;
          }
        }
        if (!yes) {
          tempans = -1;
          break;
        }
      }
      if (tempans != -1) ans = min(ans, tempans);
    }
  }
  (ans > n) ? cout << -1 : cout << ans;
}
