#include <bits/stdc++.h>
using namespace std;
int n, res, a[100000],
    change[2][9] = {{0, 1, -1, 0, 1, -1, 0, 1, -1},
                    {0, 0, 0, 1, 1, 1, -1, -1, -1}};
int cnt(int x, int d) {
  d = x - d;
  x = x + d;
  int res = 0;
  for (int i = 2; i < n; i++, x += d)
    if (a[i] + 1 == x || a[i] - 1 == x)
      res++;
    else if (a[i] != x)
      return n + 1;
  return res;
}
int main() {
  cin >> n;
  if (n < 3) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < n; i++) cin >> a[i];
  res = n + 1;
  for (int i = 0; i < 9; i++)
    res = min(res, cnt(a[1] + change[1][i], a[0] + change[0][i]) +
                       (change[1][i] != 0) + (change[0][i] != 0));
  if (res > n)
    cout << -1;
  else
    cout << res;
}
