#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int LG = 21;
const long long mod = 1e9 + 7;
vector<int> gr[N];
int par[N][LG];
char used[N];
void solve() {
  int n, m;
  cin >> n;
  vector<long long> b(n);
  for (auto& x : b) cin >> x;
  if (n < 3) {
    cout << 0;
    return;
  }
  int ans = LONG_MAX;
  for (int i = -1; i < 2; ++i) {
    for (int j = -1; j < 2; ++j) {
      bool fl = true;
      int cnt = bool(i) + bool(j);
      int last = b[1] + j;
      for (int k = 2; k < n && fl; ++k) {
        if (b[k] - last == b[1] + j - b[0] - i) {
          last = b[k];
          continue;
        }
        bool ok = false;
        for (int l = -1; l < 2; ++l) {
          if (!l) continue;
          if (b[k] + l - last == b[1] + j - b[0] - i) {
            last = b[k] + l;
            ok = true;
            break;
          }
        }
        if (!ok) fl = false;
        cnt++;
      }
      if (fl) {
        ans = min(ans, cnt);
      }
    }
  }
  if (ans == LONG_MAX) {
    cout << -1;
  } else {
    cout << ans;
  }
}
int main() {
  solve();
  return 0;
}
