#include <bits/stdc++.h>
using namespace std;
bool isprime(long long int n) {
  long long int i, j;
  if (n == 1) return 0;
  for (i = 2; i * i <= n; i++) {
    if (n % i == 0) return 0;
  }
  return 1;
}
long long int power(long long int x, long long int n, long long int mod) {
  if (x == 0) return 0;
  if (n == 0) return 1;
  if (n == 1) return x % mod;
  if (n % 2 == 0) {
    long long int temp = power(x, n / 2, mod);
    return (temp % mod * temp % mod) % mod;
  } else {
    long long int temp = power(x, n / 2, mod);
    return (x % mod * ((temp % mod * temp % mod) % mod) % mod) % mod;
  }
}
long long int modInverse(long long int a, long long int m) {
  return power(a, m - 2, m);
}
long long int findParent(long long int i, long long int parent[]) {
  if (parent[parent[i]] != parent[i]) parent[i] = findParent(parent[i], parent);
  return parent[i];
}
void unionNodes(long long int a, long long int b, long long int parent[],
                long long int size[]) {
  long long int parent_a = findParent(a, parent),
                parent_b = findParent(b, parent);
  if (parent_a == parent_b) return;
  if (size[parent_a] >= size[parent_b]) {
    size[parent_a] += size[parent_b];
    parent[parent_b] = parent_a;
  } else {
    size[parent_b] += size[parent_a];
    parent[parent_a] = parent_b;
  }
  return;
}
int main() {
  long long int n, i, j, ans = 1000000007, g = 0;
  cin >> n;
  long long int arr[n];
  for (i = 0; i < n; i++) cin >> arr[i];
  if (n == 1 || n == 2)
    cout << 0 << '\n';
  else {
    vector<pair<long long int, long long int> > v;
    v.push_back(make_pair(0, 0));
    v.push_back(make_pair(0, 1));
    v.push_back(make_pair(0, -1));
    v.push_back(make_pair(1, 0));
    v.push_back(make_pair(1, 1));
    v.push_back(make_pair(1, -1));
    v.push_back(make_pair(-1, 0));
    v.push_back(make_pair(-1, 1));
    v.push_back(make_pair(-1, -1));
    for (j = 0; j < 9; j++) {
      long long int temp = 0;
      g = 0;
      long long int x = arr[0];
      long long int y = arr[1];
      if (v[j].first != 0) temp++;
      if (v[j].second != 0) temp++;
      x = arr[0] + v[j].first;
      y = arr[1] + v[j].second;
      long long int diff = y - x;
      long long int last = y;
      for (i = 2; i < n; i++) {
        if (arr[i] - last == diff) {
          last = arr[i];
          continue;
        } else if (arr[i] + 1 - last == diff) {
          last = arr[i] + (long long int)1;
          temp++;
          continue;
        } else if (arr[i] - 1 - last == diff) {
          last = arr[i] - (long long int)1;
          temp++;
          continue;
        } else {
          g++;
          break;
        }
      }
      if (g != 0)
        g = 0;
      else
        ans = min(ans, temp);
    }
    if (ans == 1000000007)
      cout << -1 << '\n';
    else
      cout << ans << '\n';
  }
  return 0;
}
