#include <bits/stdc++.h>
using namespace std;
long long A[200050];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%I64d", &A[i]);
  if (n == 1) return 0 * printf("0\n");
  int dx[] = {-1, 0, 1}, dy[] = {-1, 0, 1};
  int ans = 1000000;
  for (int i = 0; i < 3; ++i)
    for (int j = 0; j < 3; ++j) {
      long long cur = A[n - 1] + dy[j] - (A[0] + dx[i]);
      if (cur % (n - 1)) continue;
      long long t = cur / (n - 1);
      long long h = A[0] + dx[i];
      bool ok = true;
      int cnt = 0;
      for (int k = 0; k < n; ++k, h += t) {
        if (A[k] - h > 1 || A[k] - h < -1) {
          ok = false;
          break;
        } else if (A[k] != h)
          ++cnt;
      }
      if (ok) ans = min(ans, cnt);
    }
  if (ans == 1000000)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
