#include <bits/stdc++.h>
using namespace std;
int to[9][2] = {{1, 0}, {-1, 0}, {0, 0},   {1, 1}, {-1, 1},
                {0, 1}, {1, -1}, {-1, -1}, {0, -1}};
int n;
int a[100005];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  if (n == 1 || n == 2) {
    cout << "0" << endl;
    return 0;
  }
  int ans = 0x3f3f3f3f;
  for (int i = 0; i < 9; i++) {
    int cnt = 0;
    int x = to[i][0], y = to[i][1];
    int u = a[1] + x;
    int v = a[2] + y;
    int d = v - u;
    if (abs(u - a[1]) != 0) cnt++;
    if (abs(v - a[2]) != 0) cnt++;
    for (int i = 3; i <= n; i++) {
      int now = u + (i - 1) * d;
      if (abs(now - a[i]) == 1) {
        cnt++;
        continue;
      } else if (abs(now - a[i]) == 0) {
        continue;
      } else {
        cnt = 0x3f3f3f3f;
        break;
      }
    }
    ans = min(ans, cnt);
  }
  if (ans == 0x3f3f3f3f)
    cout << "-1" << endl;
  else
    cout << ans << endl;
  return 0;
}
