#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> b(n);
  for (auto &x : b) cin >> x;
  int res = INT_MAX;
  if (n <= 2) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = -1; i <= 1; ++i) {
    for (int j = -1; j <= 1; ++j) {
      int cnt = 0;
      if (i) ++cnt;
      if (j) ++cnt;
      int fi = b[0] + i;
      int d = b[1] + j - (b[0] + i);
      bool ok = true;
      for (int x = 2; x < n; ++x) {
        int tmp = fi + d * x;
        if (abs(tmp - b[x]) > 1) {
          ok = false;
          break;
        }
        if (abs(tmp - b[x]) == 1) ++cnt;
      }
      if (ok) res = min(res, cnt);
    }
  }
  if (res == INT_MAX)
    cout << -1 << endl;
  else
    cout << res << endl;
  return 0;
}
