#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 20, mod = 1e9 + 7, inf = 1e9;
long long n, m, x1, d, z, t, pos, ans, sum, x, y, mixi, mini, a[MAXN], b[MAXN];
map<long long, int> mp;
int main() {
  ans = 1e7;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (n < 3) {
    cout << 0;
    return 0;
  }
  for (int i = a[0] - 1; i <= a[0] + 1; i++) {
    for (int j = a[1] - 1; j <= a[1] + 1; j++) {
      d = j - i;
      x = 0;
      if (a[0] != i) {
        x++;
      }
      if (a[1] != j) {
        x++;
      }
      for (int k = 2; k < n; k++) {
        if (i + (d * k) == a[k]) {
        } else if (i + (d * k) == a[k] - 1 || i + (d * k) == a[k] + 1) {
          x++;
        } else {
          x = inf;
        }
      }
      ans = min(ans, x);
    }
  }
  cout << (ans == 1e7 ? -1 : ans);
}
