#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 100005;
long long a[N];
long long b[N];
int main() {
  int n;
  while (cin >> n) {
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) b[i] = a[i];
    if (n == 1 || n == 2) {
      cout << "0" << endl;
      continue;
    }
    bool f = true;
    int ans = inf;
    for (int i = -1; i <= 1; i++) {
      for (int j = -1; j <= 1; j++) {
        a[0] += i;
        a[1] += j;
        int sum = 0;
        for (int k = 2; k < n; k++) {
          long long temp = a[k - 1] + (a[k - 1] - a[k - 2]);
          if (abs(temp - a[k]) <= 1) {
            if (abs(temp - a[k]) == 1) sum++;
            a[k] = temp;
          } else {
            f = false;
            break;
          }
          if (k == n - 1) {
            f = true;
            sum += abs(i);
            sum += abs(j);
          }
        }
        for (int k = 0; k < n; k++) a[k] = b[k];
        if (f) ans = min(ans, sum);
      }
    }
    if (ans != inf)
      cout << ans << endl;
    else
      cout << "-1" << endl;
  }
  return 0;
}
