#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  std::vector<long long> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<pair<long long, long long> > ch(9);
  ch[0] = make_pair(0, 0);
  ch[1] = make_pair(0, 1);
  ch[2] = make_pair(0, -1);
  ch[3] = make_pair(-1, 0);
  ch[4] = make_pair(1, 0);
  ch[5] = make_pair(-1, -1);
  ch[6] = make_pair(-1, 1);
  ch[7] = make_pair(1, -1);
  ch[8] = make_pair(1, 1);
  long long ans = n + 5, diff, t = 0, next;
  for (int i = 0; i < 9 && n > 2; i++) {
    diff = (ch[i].first + a[0]) - (ch[i].second + a[1]);
    next = ch[i].second + a[1];
    t = 0;
    if (i > 0) t = i < 5 ? 1 : 2;
    int j = 0;
    for (j = 2; j < n; j++) {
      if ((next - a[j]) == diff)
        next = a[j];
      else if ((next - a[j]) < diff && (next - a[j] + 1) == diff)
        next = a[j] - 1, t++;
      else if ((next - a[j]) > diff && (next - a[j] - 1) == diff)
        next = a[j] + 1, t++;
      else
        break;
    }
    if (j == n) ans = min(ans, t);
  }
  ans = (n > 2) ? ((ans == n + 5) ? -1 : ans) : 0;
  cout << ans << endl;
  return 0;
}
