#include <bits/stdc++.h>
using namespace std;
int main() {
  bool ans = false;
  long n, cnt = 0, min = LONG_MAX, err = 0;
  cin >> n;
  long b[100000];
  for (int i = 0; i < n; i++) cin >> b[i];
  if (n <= 2) {
    cout << 0;
    goto x;
  }
  for (int i = -1; i <= 1; i++) {
    for (int j = -1; j <= 1; j++) {
      err = 0, cnt = 0;
      int a1 = b[0] + i, a2 = b[1] + j;
      cnt = abs(i) + abs(j);
      for (int k = 2; k < n; k++) {
        int cur = a1 + (k) * (a2 - a1);
        if (abs(cur - b[k]) > 1) {
          err = 1;
          break;
        } else if (abs(cur - b[k]) <= 1 && cur != b[k]) {
          cnt++;
        }
      }
      if (err == 0) {
        if (min > cnt) {
          ans = true;
          min = cnt;
        }
      }
    }
  }
  if (ans)
    cout << min;
  else
    cout << -1;
x:
  return 0;
}
