#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t;
  cin >> t;
  vector<int> va, vb;
  for (int i = 1; i <= t; i++) {
    int x;
    cin >> x;
    va.push_back(x);
  }
  if (t <= 2)
    cout << 0 << "\n";
  else {
    int ans = 1e9;
    for (int i = -1; i <= 1; i++) {
      for (int j = -1; j <= 1; j++) {
        int first = va[0] + i;
        int second = va[1] + j;
        int diff = second - first;
        int pre = second;
        int temp = abs(i) + abs(j);
        bool flag = true;
        for (int k = 2; k < t; k++) {
          int test = abs((pre + diff) - va[k]);
          if (test <= 1) {
            pre += diff;
            temp += test;
          } else {
            flag = false;
            break;
          }
        }
        if (flag) ans = min(ans, temp);
      }
    }
    if (ans == 1e9)
      cout << -1 << "\n";
    else
      cout << ans << "\n";
  }
  return 0;
}
