#include <bits/stdc++.h>
using namespace std;
long long b[100010], a[9][3];
int n, cnt[9] = {2, 1, 2, 1, 0, 1, 2, 1, 2}, maxcnt = -1;
int dx[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1},
    dy[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> b[i];
  if (n == 1 || n == 2) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < 9; i++) {
    a[i][0] = b[0] + dx[i];
    a[i][1] = b[1] + dy[i];
    int adis = a[i][1] - a[i][0];
    for (int j = 2; j < n; j++) {
      a[i][1] += adis;
      if (b[j] == (a[i][1] - 1))
        cnt[i]++;
      else if (b[j] == (a[i][1]))
        ;
      else if (b[j] == (a[i][1] + 1))
        cnt[i]++;
      else {
        cnt[i] = -1;
        break;
      }
    }
  }
  for (int i = 0; i < 9; i++) {
    if (cnt[i] == -1) continue;
    if (maxcnt == -1) maxcnt = cnt[i];
    maxcnt = min(maxcnt, cnt[i]);
  }
  cout << maxcnt;
  return 0;
}
