#include <bits/stdc++.h>
using namespace std;
int n, a[100010], b[100010];
int main() {
  int ans = 100010;
  scanf("%d", &n);
  int p = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  p = a[n] - a[n - 1];
  for (int i = p - 2; i <= p + 2; i++) {
    for (int tj = -1; tj <= 1; tj++) {
      for (int j = 1; j <= n; j++) b[j] = a[j];
      b[1] += tj;
      int sum = (bool)tj, t = b[1];
      for (int j = 2; j <= n; j++) {
        t += i;
        if (abs(b[j] - t) > 1) {
          sum = -1;
          break;
        } else {
          sum += abs(b[j] - t);
        }
      }
      if (sum != -1) ans = min(ans, sum);
    }
  }
  if (ans > 100000) {
    printf("-1\n");
  } else {
    printf("%d\n", ans);
  }
  return 0;
}
