#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N], b[N];
int d[10], res[10];
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  if (n == 1 || n == 2) {
    cout << 0 << endl;
    return 0;
  }
  int cnt = 0;
  int dx[] = {1, 0, -1}, dy[] = {1, 0, -1};
  for (int i = 0; i < 3; ++i)
    for (int j = 0; j < 3; ++j) {
      a[1] += dx[i];
      a[2] += dy[j];
      d[cnt] = a[2] - a[1];
      res[cnt] = abs(dx[i]) + abs(dy[j]);
      memcpy(b, a, sizeof(a));
      for (int k = 3; k <= n; ++k) {
        int t = b[k] - b[k - 1];
        if (t == d[cnt])
          continue;
        else if (t + 1 == d[cnt]) {
          b[k]++;
          res[cnt]++;
          continue;
        } else if (t - 1 == d[cnt]) {
          b[k]--;
          res[cnt]++;
          continue;
        }
        res[cnt] = -1;
        break;
      }
      a[1] -= dx[i];
      a[2] -= dy[j];
      cnt++;
    }
  int ans = -1;
  sort(res, res + 9);
  for (int i = 0; i < 9; ++i)
    if (res[i] != -1 || i == 8) {
      cout << res[i] << endl;
      break;
    }
  return 0;
}
