#include <bits/stdc++.h>
using namespace std;
long long n, k, a[100005], b[100005], ans;
void go(int x, int y) {
  long long an = 0;
  for (int i = 1; i <= n; i++) b[i] = a[i];
  b[1] += x;
  b[2] += y;
  int cons = b[2] - b[1];
  if (x != 0) an++;
  if (y != 0) an++;
  for (int i = 3; i <= n; i++) {
    if (b[i - 1] + cons == b[i] + 1) {
      an++;
      b[i]++;
      continue;
    } else if (b[i - 1] + cons == b[i] - 1) {
      an++;
      b[i]--;
      continue;
    } else if (b[i - 1] + cons == b[i])
      continue;
    return;
  }
  ans = min(ans, an);
}
int main() {
  cin >> n;
  if (n <= 2) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) cin >> a[i];
  ans = n + 1;
  go(0, 0);
  go(0, 1);
  go(1, 0);
  go(1, 1);
  go(-1, 0);
  go(0, -1);
  go(-1, -1);
  go(1, -1);
  go(-1, 1);
  if (ans == n + 1)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
