#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long int b[n + 1];
  for (int i = 1; i <= n; i++) cin >> b[i];
  long long int ap[n + 1];
  long long int cnt[10] = {0};
  cnt[0] = -1;
  int temp = 1;
  for (int i = -1; i <= 1; i++) {
    ap[1] = b[1];
    ap[1] += i;
    for (int j = -1; j <= 1; j++) {
      ap[2] = b[2];
      ap[2] += j;
      for (int k = 3; k <= n; k++) {
        ap[k] = ap[k - 1] + ap[2] - ap[1];
        if (abs(ap[k] - b[k]) > 1) {
          cnt[temp] = -1;
          break;
        } else {
          if (abs(ap[k] - b[k]) == 1) cnt[temp]++;
        }
      }
      if (ap[1] != b[1] && cnt[temp] != -1) {
        if (ap[2] != b[2])
          cnt[temp] += 2;
        else
          cnt[temp]++;
      } else {
        if (ap[2] != b[2] && cnt[temp] != -1) cnt[temp]++;
      }
      temp++;
    }
  }
  long long int mi = 1000000000000000;
  for (int i = 1; i <= 9; i++) {
    if (cnt[i] > -1) {
      mi = min(mi, cnt[i]);
    }
  }
  if (mi < 1000000000000000)
    cout << mi << endl;
  else
    cout << -1 << endl;
  return 0;
}
