#include <bits/stdc++.h>
using namespace std;
long long b[100010];
int ans = 0x3f3f3f3f;
int n;
void dfs(int k, int val) {
  if (k == 3) {
    bool flag = true;
    int res = val;
    long long d = b[2] - b[1];
    for (int i = 3; i <= n; i++) {
      long long r = b[1] + d * (i - 1);
      if (b[i] == r) continue;
      if (abs(r - b[i]) <= 1)
        res++;
      else
        flag = false;
    }
    if (flag) ans = min(ans, res);
    return;
  }
  dfs(k + 1, val);
  b[k]++;
  dfs(k + 1, val + 1);
  b[k]--;
  b[k]--;
  dfs(k + 1, val + 1);
  b[k]++;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%lld", &b[i]);
  if (n <= 2)
    ans = 0;
  else
    dfs(1, 0);
  if (ans == 0x3f3f3f3f) ans = -1;
  printf("%d\n", ans);
  return 0;
}
