#include <bits/stdc++.h>
using namespace std;
long long int seq[100100];
map<long long int, map<long long int, long long int>> pd[100100];
int n;
long long int solve(int ind, long long int ant, long long int dif) {
  if (ind == n + 1) return 0;
  long long int res = 987654321;
  if (pd[ind][ant].find(dif) != pd[ind][ant].end()) return pd[ind][ant][dif];
  if (ind == 1) {
    for (int i = -1; i <= 1; i++) {
      res = min(res, (i != 0) + solve(ind + 1, seq[ind] + i, 987654321));
    }
  }
  if (ind == 2) {
    for (int i = -1; i <= 1; i++) {
      res =
          min(res, (i != 0) + solve(ind + 1, seq[ind] + i, seq[ind] + i - ant));
    }
  }
  for (int i = -1; i <= 1; i++) {
    if (seq[ind] + i - ant == dif) {
      res = min(res, (i != 0) + solve(ind + 1, seq[ind] + i, dif));
    }
  }
  return pd[ind][ant][dif] = res;
}
int main() {
  cin >> n;
  int i;
  for (i = 1; i <= n; i++) {
    cin >> seq[i];
  }
  long long int r = solve(1, 0, 987654321);
  if (r != 987654321) {
    cout << r << endl;
  } else {
    cout << -1 << endl;
  }
}
