#include <bits/stdc++.h>
using namespace std;
int n, k, i, j, p;
int b[101010], a[100100], mii = 0x3f3f3f3f;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  if (n == 1 || n == 2) {
    for (i = 1; i <= n; i++) {
      cin >> a[i];
    }
    cout << 0;
    return 0;
  }
  k = 0;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int y;
  for (i = -1; i <= 1; i++) {
    for (j = -1; j <= 1; j++) {
      y = 1;
      int s = abs(i) + abs(j);
      b[1] = a[1] + i;
      b[2] = a[2] + j;
      p = b[2] - b[1];
      for (k = 3; k <= n; k++) {
        b[k] = b[k - 1] + p;
        if (abs(b[k] - a[k]) > 1) {
          y = 0;
          break;
        }
        if (b[k] != a[k]) {
          s++;
        }
      }
      if (y) {
        mii = min(mii, s);
      }
    }
  }
  if (mii != 0x3f3f3f3f)
    cout << mii;
  else
    cout << -1;
}
