#include <bits/stdc++.h>
using namespace std;
int n, inf = 1000000009;
int a[500009];
int check(int id, int val, int last) {
  if (id == n) return 0;
  int ret = 0;
  if (a[id] - last == val)
    ret = check(id + 1, val, a[id]);
  else if (a[id] - last == val + 1)
    ret = check(id + 1, val, a[id] - 1) + 1;
  else if (a[id] - last == val - 1)
    ret = check(id + 1, val, a[id] + 1) + 1;
  else
    ret = inf;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int val = a[1] - a[0];
  int x = min(check(1, val + 1, a[0] - 1) + 1, check(1, val + 2, a[0] - 1) + 1);
  int y = min(check(1, val - 1, a[0] + 1) + 1, check(1, val - 2, a[0] + 1) + 1);
  int u = min(check(1, val + 1, a[0]), check(1, val - 1, a[0]));
  int q = min(check(1, val, a[0] - 1) + 1, check(1, val, a[0] + 1) + 1);
  int z = min(min(check(1, val, a[0]), u), min(x, y));
  z = min(z, q);
  if (z == inf)
    cout << -1 << endl;
  else
    cout << z << endl;
}
