#include <bits/stdc++.h>
using namespace std;
int in() {
  int a;
  scanf("%d", &a);
  return a;
}
long long inll() {
  long long a;
  scanf("%lld", &a);
  return a;
}
double ind() {
  double a;
  scanf("%lf", &a);
  return a;
}
long double inld() {
  long double a;
  scanf("%Lf", &a);
  return a;
}
long long a[200005];
long long b[200005];
int n;
int df[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
int ds[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
int main() {
  n = in();
  for (int i = 0; i < n; i++) {
    a[i] = inll();
  }
  int cnt, res = 200005;
  for (int k = 0; k < 9; k++) {
    cnt = 0;
    b[0] = a[0] + df[k];
    b[1] = a[1] + ds[k];
    if (df[k] != 0) cnt++;
    if (ds[k] != 0) cnt++;
    for (int i = 2; i < n; i++) {
      if (abs(b[i - 1] + b[1] - b[0] - a[i]) <= 1) {
        b[i] = b[i - 1] + b[1] - b[0];
        if (abs(b[i - 1] + b[1] - b[0] - a[i]) != 0) {
          cnt++;
        }
      } else {
        cnt = 200005;
        break;
      }
    }
    res = min(res, cnt);
  }
  cout << (res == 200005 ? -1 : res) << endl;
  return 0;
}
