#include <bits/stdc++.h>
using namespace std;
set<long long>::iterator it;
multiset<long long>::iterator itr;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long t;
  t = 1;
  while (t--) {
    long long n;
    cin >> n;
    if (n == 1 || n == 2) {
      cout << 0 << endl;
      return 0;
    }
    long long arr[n + 1];
    vector<pair<long long, long long>> v;
    for (long long(i) = 0; (i) < (n); (i)++) cin >> arr[i + 1];
    vector<long long> t;
    for (long long i = -1; i <= 1; i++) {
      for (long long j = -1; j <= 1; j++) {
        v.push_back(make_pair(arr[1] + i, arr[n] + j));
      }
    }
    long long minn = INT_MAX;
    long long ans = -1;
    for (long long i = 0; i < v.size(); i++) {
      long long cnt = 0;
      long long a1 = v[i].first;
      long long an = v[i].second;
      if (a1 != arr[1]) cnt++;
      if (an != arr[n]) cnt++;
      if ((an - a1) % (n - 1) == 0) {
        long long d = (an - a1) / (n - 1);
        long long fl = -1;
        for (long long j = 2; j <= n - 1; j++) {
          if (arr[j] == a1 + (j - 1) * d) {
            continue;
          } else if (abs(arr[j] - (a1 + (j - 1) * d)) == 1) {
            cnt++;
          } else {
            fl = 1;
            break;
          }
        }
        if (fl == -1) {
          minn = min(cnt, minn);
          ans = minn;
        }
      } else {
        continue;
      }
    }
    if (ans == -1) {
      cout << ans << endl;
    } else {
      cout << minn << endl;
    }
  }
}
