#include <bits/stdc++.h>
using namespace std;
int a[100005];
int b[100005];
int n;
int hsy(int d, int q) {
  int f = 1;
  d = d / (n - 1);
  for (int i = 2; i <= n; i++) {
    if (b[i] - b[i - 1] == d + 1)
      b[i]--, q++;
    else if (b[i] - b[i - 1] == d - 1)
      b[i]++, q++;
    else if (b[i] - b[i - 1] == d)
      continue;
    else {
      f = 0;
      break;
    }
  }
  for (int i = 1; i <= n; i++) b[i] = a[i];
  if (f) return q;
  return 0x7fffffff;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], b[i] = a[i];
  if (n == 1 || n == 2) {
    puts("0");
  } else {
    int ans = 0x7fffffff;
    for (int i = -1; i <= 1; i++) {
      for (int j = -1; j <= 1; j++) {
        int d = (a[n] + i) - (a[1] + j);
        if (d % (n - 1) == 0)
          b[n] = a[n] + i, b[1] = a[1] + j,
          ans = min(hsy(d, abs(i) + abs(j)), ans);
      }
    }
    if (ans == 0x7fffffff)
      puts("-1");
    else
      cout << ans << endl;
  }
}
