#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn];
int b[maxn];
int d[] = {0, 1, -1};
int main() {
  ios::sync_with_stdio(false);
  int N;
  while (cin >> N) {
    for (int i = 0; i < N; i++) cin >> a[i];
    if (N == 1 || N == 2)
      cout << 0 << endl;
    else {
      int ans = 0;
      int res = 0x3f3f3f3f;
      for (int i = 0; i < 3; i++) {
        b[0] = a[0] + d[i];
        for (int j = 0; j < 3; j++) {
          b[1] = a[1] + d[j];
          int cha = b[1] - b[0];
          bool flag = false;
          ans = 0;
          if (i != 0) ans++;
          if (j != 0) ans++;
          for (int p = 2; p < N; p++) {
            b[p] = b[p - 1] + cha;
            if (abs(a[p] - b[p]) > 1) {
              flag = true;
              break;
            }
            if (b[p] != a[p]) ans++;
          }
          if (flag) continue;
          res = min(res, ans);
        }
      }
      if (res == 0x3f3f3f3f)
        cout << -1 << endl;
      else
        cout << res << endl;
    }
  }
  return 0;
}
