#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
long long int logy(long long int x, long long int y) {
  return ceil((long double)(log(x) / log(y)));
}
long long int powe(long long int a, long long int b) {
  long long int re = 1;
  while (b) {
    if (b & 1) re = (re * a);
    a = (a * a);
    b = b >> 1;
  }
  return re;
}
bool flag = 0, flag1 = 0, flag2 = 0;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int tt = 1;
  while (tt--) {
    long long int n;
    cin >> n;
    long long int a[n], fans = 1000000007;
    for (int i = 0; i < n; i++) cin >> a[i];
    if (n <= 2) {
      cout << 0;
      return 0;
    }
    for (long long int k = -1; k < 2; k++)
      for (long long int i = -1; i < 2; i++) {
        flag = 0;
        long long int ans = abs(k) + abs(i);
        a[0] += k;
        a[1] += i;
        long long int want = a[1] - a[0];
        for (long long int j = 2; j < n; j++) {
          if (abs(j * want - a[j] + a[0]) > 1)
            flag = 1;
          else if ((abs(j * want - a[j] + a[0]) == 1))
            ans++;
        }
        if (flag == 0) fans = min(ans, fans);
        a[0] -= k;
        a[1] -= i;
      }
    if (fans == 1000000007)
      cout << -1;
    else
      cout << fans;
  }
  return 0;
}
