#include <bits/stdc++.h>
using namespace std;
const int INF = 1 * 1e9;
long long cntr(vector<long long> a, long long x, long long y) {
  a[0] += x;
  a[1] += y;
  int diff = a[1] - a[0], cnt = abs(x) + abs(y);
  for (int i = 2; i < a.size(); ++i) {
    cnt += abs(a[i] - a[i - 1] - diff);
    a[i] = a[i - 1] + diff;
  }
  return cnt;
}
bool check(vector<long long>& a) {
  long long mx = 0;
  long long mi = 0;
  for (int i = 1; i < a.size(); ++i) {
    mx = max(a[i] - a[i - 1], mx);
    mi = min(a[i] - a[i - 1], mi);
  }
  if (mx > 0 && mi < 0) {
    return 0;
  }
  return 1;
}
int main() {
  cout.tie(0);
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  if (n <= 2) {
    cout << 0;
    return 0;
  }
  long long ans = n + 1;
  for (long long x = -1; x <= 1; ++x) {
    for (long long y = -1; y <= 1; ++y) {
      long long cur = cntr(a, x, y);
      if (cur < 0) {
        cur = n + 1;
      }
      ans = min(cur, ans);
    }
  }
  if (ans > n || ans < 0) {
    ans = -1;
  }
  cout << ans;
  return 0;
}
