#include <bits/stdc++.h>
using namespace std;
const long long N = 1e9 + 7;
long long pow(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = ((res) * (x));
    res %= N;
    y = y >> 1;
    x = ((x) * (x));
  }
  return res;
}
long long powm(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
  }
  if (n <= 2) {
    cout << 0;
    return;
  }
  long long ans = (long long)1e18;
  for (long long i = -1; i <= 1; i++) {
    for (long long j = -1; j <= 1; j++) {
      vector<long long> temp;
      temp.assign(v.begin(), v.end());
      temp[0] += i;
      temp[1] += j;
      long long cnt = 0;
      if (i != 0) cnt++;
      if (j != 0) cnt++;
      long long flag = 0;
      long long s = temp[1] - temp[0];
      for (long long k = 2; k < n; k++) {
        if (temp[k] - temp[k - 1] == s) {
        } else if (temp[k] - temp[k - 1] - 1 == s) {
          temp[k] -= 1;
          cnt++;
        } else if (temp[k] - temp[k - 1] + 1 == s) {
          temp[k] += 1;
          cnt++;
        } else {
          flag = 1;
          break;
        }
      }
      if (flag == 0) {
        ans = min(ans, cnt);
      }
    }
  }
  if (ans == (long long)1e18) {
    cout << -1;
    return;
  }
  cout << ans;
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
}
