#include <bits/stdc++.h>
template <class T>
inline T lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / __gcd(a, b)) * b;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T ncr(T n, T r) {
  return n * (n - 1) / r;
}
using namespace std;
vector<long long int> v;
vector<long long int> vd(100001);
int n, ans = 100007;
int check(long long int dif) {
  int ret = 0;
  for (int i = 0; i < n; i++) {
    int d = abs(v[i] - vd[i]);
    if (d > 1)
      return -1;
    else {
      if (d == 1) ret++;
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  long long int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  if (n <= 2) {
    cout << 0;
    return 0;
  }
  for (int i = v[0] - 1; i <= v[0] + 1; i++) {
    for (int j = v[1] - 1; j <= v[1] + 1; j++) {
      long long int dif = j - i;
      vd[0] = i;
      vd[1] = j;
      for (int k = 2; k < n; k++) {
        vd[k] = vd[k - 1] + dif;
      }
      int ret = check(dif);
      if (ret != -1) {
        ans = min(ans, ret);
      }
    }
  }
  if (ans == 100007)
    cout << -1 << endl;
  else
    cout << ans;
  return 0;
}
