#include <bits/stdc++.h>
using namespace std;
int str[100010];
int main() {
  int n, cnt = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> str[i];
  if (n == 2) {
    cout << 0 << endl;
    return 0;
  }
  int minn = 100000000;
  for (int i = -1; i <= 1; i++) {
    for (int j = -1; j <= 1; j++) {
      cnt = 0;
      if (abs(i) == 1) cnt++;
      if (abs(j) == 1) cnt++;
      int cha = str[2] + j - str[1] - i;
      int m = str[2] + j;
      int flag = 0;
      for (int k = 3; k <= n; k++) {
        m += cha;
        if (abs(str[k] - m) > 1) {
          flag = 1;
          break;
        }
        if (abs(str[k] - m) == 1) cnt++;
      }
      if (cnt < minn && !flag) minn = cnt;
    }
  }
  if (minn == 100000000)
    cout << -1 << endl;
  else
    cout << minn << endl;
  return 0;
}
