#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int a[maxn], b[maxn];
int n;
void cop() {
  for (int i = 1; i <= n; i++) {
    b[i] = a[i];
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  if (n == 1 || n == 2) {
    cout << "0" << endl;
    return 0;
  }
  int ans = n + 1;
  for (int x = -1; x <= 1; x++) {
    for (int y = -1; y <= 1; y++) {
      int res = abs(x) + abs(y);
      cop();
      b[2] += x;
      b[1] += y;
      int tmp = b[2] - b[1];
      int flag = 1;
      for (int i = 3; i <= n; i++) {
        if (b[i] - b[i - 1] == tmp) {
          continue;
        }
        if (b[i] - 1 - b[i - 1] == tmp) {
          b[i]--;
          res++;
          continue;
        }
        if (b[i] + 1 - b[i - 1] == tmp) {
          b[i]++;
          res++;
          continue;
        }
        flag = 0;
        break;
      }
      if (flag) {
        ans = min(ans, res);
      }
    }
  }
  if (ans == n + 1) {
    cout << "-1" << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
