#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n;
long long b[maxn];
int judge(long long mp, long long last) {
  int ans = 0;
  for (int i = 2; i < n; i++) {
    long long tmp = mp;
    long long now = abs(mp - b[i]);
    if (now == 0) {
      mp = mp * 2 - last;
    } else if (now == 1) {
      mp = mp * 2 - last;
      ++ans;
    } else
      return -1;
    last = tmp;
  }
  return ans;
}
void solve() {
  int ans = INT_MAX;
  for (int i = -1; i <= 1; i++) {
    for (int j = -1; j <= 1; j++) {
      long long first = b[0] + i;
      long long last = b[1] + j;
      int tmp = judge(last + (last - first), last);
      if (tmp == -1) continue;
      tmp += (i != 0) + (j != 0);
      ans = min(ans, tmp);
    }
  }
  if (ans == INT_MAX) ans = -1;
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> b[i];
  if (n <= 2)
    cout << 0 << endl;
  else
    solve();
  return 0;
}
