#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<long int> v, res;
  long int n, i, x, j, k;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  if (n < 3) {
    cout << 0;
    return 0;
  }
  for (j = v[0] - 1; j <= v[0] + 1; j++) {
    for (k = v[n - 1] - 1; k <= v[n - 1] + 1; k++) {
      if ((k - j) % (n - 1) != 0) continue;
      long int st = j, ans = 0, flag = 0;
      long int d = (k - j) / (n - 1);
      vector<long int> v2 = v;
      if (v2[0] != st) {
        ans++;
        v2[0] = st;
      }
      for (i = 1; i < n; i++) {
        st += d;
        if (abs(v2[i] - st) > 1) {
          flag = 1;
          break;
        }
        if (v2[i] == st) continue;
        v2[i] = st;
        ans++;
      }
      if (flag == 0) {
        res.push_back(ans);
      }
    }
  }
  if (res.empty()) {
    cout << -1 << endl;
    return 0;
  }
  sort(res.begin(), res.end());
  cout << res[0] << endl;
  return 0;
}
