#include <bits/stdc++.h>
using namespace std;
long long arr[] = {2, 1, 0, -1, -2};
long long seq[100005];
long long n;
long long check(long long cnt) {
  long long p[] = {+1, 0, -1};
  vector<long long> v;
  long long ret = LONG_MAX;
  for (long long i = 0; i < 3; i++) {
    long long ans = 0;
    int flag = 0;
    long long a0 = seq[0] + p[i];
    v.push_back(a0);
    if (i != 1) ans++;
    for (long long j = 1; j < n; j++) {
      v.push_back(seq[j]);
      if (v[j - 1] - v[j] == cnt + 1) {
        ans++;
        v[j] += 1;
      } else if (v[j - 1] - v[j] == cnt - 1) {
        ans++;
        v[j] -= 1;
      } else if (v[j - 1] - v[j] != cnt) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      ret = min(ret, ans);
    }
    v.clear();
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  ;
  cin >> n;
  long long mun = LONG_MAX;
  for (long long i = 0; i < n; i++) {
    cin >> seq[i];
    if (i > 0) mun = min(mun, seq[i - 1] - seq[i]);
  }
  long long ans = 1e7;
  for (long long i = 0; i < 5; i++) {
    ans = min(ans, check(mun + arr[i]));
  }
  if (ans != 10000000)
    cout << ans << '\n';
  else
    cout << "-1" << '\n';
}
