#include <bits/stdc++.h>
using namespace std;
long long Set(long long n, long long pos) { return n = n | (1LL << pos); }
long long reset(long long n, long long pos) { return n = n & ~(1LL << pos); }
bool check(long long n, long long pos) { return (bool)(n & (1LL << pos)); }
long long mul(long long a, long long b) {
  long long c;
  c = (a % 1000000007 * b % 1000000007) % 1000000007;
  return c;
}
long long add(long long a, long long b) {
  long long c;
  c = (a % 1000000007 + b % 1000000007) % 1000000007;
  return c;
}
long long sub(long long a, long long b) {
  long long c;
  c = ((a % 1000000007 - b % 1000000007) % 1000000007 + 1000000007) %
      1000000007;
  return c;
}
long long power(long long x, long long y) {
  long long res = 1;
  x = x;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long exgcd(long long x, long long y, long long &a, long long &b) {
  int flag = 0;
  long long t, la = 1, lb = 0, ra = 0, rb = 1;
  while (x % y) {
    if (flag == 0)
      la -= x / y * ra, lb -= x / y * rb;
    else
      ra -= x / y * la, rb -= x / y * lb;
    t = x, x = y, y = t % y;
    flag = 1 - flag;
  }
  if (flag == 0)
    a = ra, b = rb;
  else
    a = la, b = lb;
  return y;
}
long long b[100009], n;
long long solve(long long num, long long indx, long long dif) {
  if (indx > n) return 0;
  long long state = 0, s1 = 1e18, s2 = 1e18, s3 = 1e18;
  if (indx == 2) {
    s1 = solve(b[indx], indx + 1, b[indx] - num);
    s2 = solve(b[indx] + 1, indx + 1, b[indx] + 1 - num);
    s3 = solve(b[indx] - 1, indx + 1, b[indx] - 1 - num);
  } else {
    if (b[indx] - num == dif) s1 = solve(b[indx], indx + 1, b[indx] - num);
    if (b[indx] + 1 - num == dif)
      s2 = solve(b[indx] + 1, indx + 1, b[indx] + 1 - num);
    if (b[indx] - 1 - num == dif)
      s3 = solve(b[indx] - 1, indx + 1, b[indx] - 1 - num);
  }
  s2++, s3++;
  state = min(s1, s2);
  state = min(state, s3);
  return state;
}
int main() {
  cin >> n;
  long long dif;
  bool chk = 1;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &b[i]);
    if (i == 2) dif = b[2] - b[1];
    if (i > 2) {
      if (dif != b[i] - b[i - 1]) chk = 0;
    }
  }
  if (n <= 2 || chk) {
    printf("0\n");
    return 0;
  }
  long long ans = 0;
  long long a1 = solve(b[1] + 1, 2, 0);
  long long a2 = solve(b[1], 2, 0);
  long long a3 = solve(b[1] - 1, 2, 0);
  a1++, a3++;
  ans = min(a1, a2);
  ans = min(ans, a3);
  if (ans >= 1e18) {
    printf("-1\n");
    return 0;
  } else
    printf("%lld\n", ans);
  return 0;
}
