#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e18;
vector<long long> a(1e5 + 7);
long long n;
long long solve(long long dif, vector<long long> b, long long x, long long y) {
  long long ans = 0;
  b[0] = x, b[1] = y;
  if (y - x != dif) return INF;
  for (int i = 2; i < n; ++i) {
    long long add = b[i - 1] + dif;
    if (abs(add - b[i]) > 1) return INF;
    if (b[i] - b[i - 1] != dif) ++ans;
    b[i] = add;
  }
  for (int i = 0; i < n; ++i)
    if (b[i] < 0 || b[i] > 1e9 + 1) return INF;
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  long long dif = 2e9, ans = INF;
  dif = a[1] - a[0];
  for (int i = dif - 2; i <= dif + 2; ++i)
    for (long long x = a[0] - 1; x <= a[0] + 1; ++x)
      for (long long y = a[1] - 1; y <= a[1] + 1; ++y)
        ans = min(ans, solve(y - x, a, x, y) + ((x != a[0]) + (y != a[1])));
  cout << (ans == INF ? -1 : ans);
}
