#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans = -1, d, t;
  bool cond;
  cin >> n;
  vector<int> a(n);
  vector<int> _a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  if (n < 3) {
    cout << 0;
    return 0;
  }
  for (int i = -1; i <= 1; i++) {
    for (int j = -1; j <= 1; j++) {
      _a[0] = a[0] + i;
      _a[1] = a[1] + j;
      d = _a[0] - _a[1];
      cond = true;
      t = 0;
      for (int k = 2; k < n; k++) {
        _a[k] = _a[k - 1] - d;
      }
      for (int k = 0; k < n; k++) {
        if (_a[k] == a[k])
          continue;
        else if (abs(_a[k] - a[k]) == 1)
          t++;
        else
          cond = false;
      }
      if (cond && (ans == -1 || ans > t)) ans = t;
    }
  }
  cout << ans;
  return 0;
}
