#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b);
long long lcm(long long a, long long b);
vector<long long> prime;
bitset<000000 + 1> isPrime;
vector<long long> primeFactor;
vector<long long> uniqueprimeFactor;
vector<long long> divisors[000000 + 1];
vector<long long> divNum;
long long phiValue[000000 + 1];
void seive(long long lim);
void primeFactorial(long long n);
void eulerPhi(long long lim);
void divGenerator(long long n);
void div(long long n);
long long bigMod(long long b, long long p, long long m);
long long nCr(long long n, long long r);
long long string2int(string str);
string int2string(long long num);
long long bs(long long arr[], long long l, long long r, long long x);
long long prevMatch(long long arr[], long long l, long long r, long long x);
long long range(long long arr[], long long l, long long r, long long left,
                long long right);
long long firstMarched(long long arr[], long long l, long long r, long long x);
long long vbs(vector<long long> arr, long long l, long long r, long long x);
long long vprevMatch(vector<long long> arr, long long l, long long r,
                     long long x);
long long vrange(vector<long long> arr, long long l, long long r,
                 long long left, long long right);
long long vfirstMarched(vector<long long> arr, long long l, long long r,
                        long long x);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> a;
  for (long long i = 0; i < n; ++i) {
    long long nabil;
    cin >> nabil;
    a.push_back(nabil);
  }
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  long long mx, mi;
  mx = abs(a[n - 1] - a[0]) + 2;
  mi = abs(a[n - 1] - a[0]) - 2;
  mx = mx / (n - 1);
  mi = ceil((double)mi / double(n - 1));
  vector<long long> v;
  for (long long i = mi; i <= mx; ++i) {
    bool xt = true, yt = true, zt = true;
    long long cx = 1, cy = 0, cz = 1, x = a[0] + 1, y = a[0], z = a[0] - 1,
              j = 1;
    while (j < n) {
      x = x + i;
      y = y + i;
      z = z + i;
      if (abs(x - a[j]) > 1) {
        xt = false;
      } else {
        if (abs(x - a[j]) == 1) {
          cx++;
        }
      }
      if (abs(y - a[j]) > 1) {
        yt = false;
      } else {
        if (abs(y - a[j]) == 1) {
          cy++;
        }
      }
      if (abs(z - a[j]) > 1) {
        zt = false;
      } else {
        if (abs(z - a[j]) == 1) {
          cz++;
        }
      }
      j++;
    }
    if (xt) {
      v.push_back(cx);
    }
    if (yt) {
      v.push_back(cy);
    }
    if (zt) {
      v.push_back(cz);
    }
  }
  reverse(a.begin(), a.end());
  for (long long i = mi; i <= mx; ++i) {
    bool xt = true, yt = true, zt = true;
    long long cx = 1, cy = 0, cz = 1, x = a[0] + 1, y = a[0], z = a[0] - 1,
              j = 1;
    while (j < n) {
      x = x + i;
      y = y + i;
      z = z + i;
      if (abs(x - a[j]) > 1) {
        xt = false;
      } else {
        if (abs(x - a[j]) == 1) {
          cx++;
        }
      }
      if (abs(y - a[j]) > 1) {
        yt = false;
      } else {
        if (abs(y - a[j]) == 1) {
          cy++;
        }
      }
      if (abs(z - a[j]) > 1) {
        zt = false;
      } else {
        if (abs(z - a[j]) == 1) {
          cz++;
        }
      }
      j++;
    }
    if (xt) {
      v.push_back(cx);
    }
    if (yt) {
      v.push_back(cy);
    }
    if (zt) {
      v.push_back(cz);
    }
  }
  sort(v.begin(), v.end());
  if (!v.empty()) {
    cout << v[0] << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
long long gcd(long long a, long long b) {
  if (a % b == 0) {
    return b;
  }
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
  long long ret = ((a / gcd(a, b)) * b);
  return ret;
}
void seive(long long lim) {
  isPrime.set();
  prime.push_back(2);
  for (long long i = 3; i <= lim; i += 2) {
    if (isPrime[i]) {
      prime.push_back(i);
      for (long long j = i * i; j <= lim; j += (i << 1)) {
        isPrime[j] = 0;
      }
    }
  }
}
void primeFactorial(long long n) {
  for (long long i = 0; prime[i] * prime[i] <= n; i++) {
    long long cnt = 0;
    while (n % prime[i] == 0) {
      n = n / prime[i];
      cnt++;
      primeFactor.push_back(prime[i]);
    }
    if (cnt > 0) {
      uniqueprimeFactor.push_back(prime[i]);
    }
    if (n == 1) {
      break;
    }
  }
  if (n > 1) {
    primeFactor.push_back(n);
    uniqueprimeFactor.push_back(n);
  }
}
void eulerPhi(long long lim) {
  for (long long i = 0; i <= lim; ++i) {
    phiValue[i] = i;
  }
  for (long long i = 2; i <= lim; ++i) {
    if (phiValue[i] == i) {
      for (long long j = i; j <= lim; j += i) {
        phiValue[j] = (phiValue[j] * (i - 1)) / i;
      }
    }
  }
  phiValue[0] = 1;
  phiValue[1] = 1;
}
long long bigMod(long long b, long long p, long long m) {
  long long y;
  if (b == 0) {
    return 0;
  }
  if (p == 0) {
    return 1;
  }
  if (p % 2 == 0) {
    y = bigMod(b, p / 2, m);
    y = (y * y) % m;
  } else {
    y = b % m;
    y = (y * bigMod(b, p - 1, m) % m) % m;
  }
  return (y + m) % m;
}
long long nCr(long long n, long long r) {
  long long p = 1, k = 1;
  if (n - r < r) {
    r = n - r;
  }
  if (r != 0) {
    while (r) {
      p *= n;
      k *= r;
      long long m = gcd(p, k);
      p /= m;
      k /= m;
      n--;
      r--;
    }
  } else {
    p = 1;
  }
  return p;
}
void divGenerator(long long n) {
  for (long long i = 1; i <= n; i++) {
    for (long long j = i; j <= n; j += i) {
      divisors[j].push_back(i);
    }
  }
}
long long string2int(string str) {
  long long cnt = 1, sum = 0;
  for (long long i = str.length() - 1; i >= 0; i--) {
    long long typcast = (int)(str[i]) - 48;
    sum = sum + typcast * cnt;
    cnt = cnt * 10;
  }
  return sum;
}
string int2string(long long num) {
  string str = "";
  while (num > 0) {
    int ch;
    ch = ((num) % 10) + 48;
    str += char(ch);
    num = num / 10;
  }
  reverse(str.begin(), str.end());
  return str;
}
void div(long long n) {
  for (long long i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      if (i != (n / i)) {
        divNum.push_back(i);
        divNum.push_back(n / i);
      } else {
        divNum.push_back(i);
      }
    }
  }
  sort(divNum.begin(), divNum.end());
}
long long bs(long long arr[], long long l, long long r, long long x) {
  long long m;
  while (l <= r) {
    m = (l + r) / 2;
    if (arr[m] == x) {
      return m;
    } else if (arr[m] < x) {
      l = m + 1;
    } else {
      r = m - 1;
    }
  }
  return -1;
}
long long vbs(vector<long long> arr, long long l, long long r, long long x) {
  long long m;
  while (l <= r) {
    m = (l + r) / 2;
    if (arr[m] == x) {
      return m;
    } else if (arr[m] < x) {
      l = m + 1;
    } else {
      r = m - 1;
    }
  }
  return -1;
}
long long prevMatch(long long arr[], long long l, long long r, long long x) {
  long long m, ret = -1;
  while (l <= r) {
    m = (l + r) / 2;
    if (arr[m] <= x) {
      ret = m;
      l = m + 1;
    } else {
      r = m - 1;
    }
  }
  return ret;
}
long long vprevMatch(vector<long long> arr, long long l, long long r,
                     long long x) {
  long long m, ret = -1;
  while (l <= r) {
    m = (l + r) / 2;
    if (arr[m] <= x) {
      ret = m;
      l = m + 1;
    } else {
      r = m - 1;
    }
  }
  return ret;
}
long long range(long long arr[], long long l, long long r, long long left,
                long long right) {
  long long ret;
  ret = prevMatch(arr, l, r, right) - prevMatch(arr, l, r, left - 1);
  return ret;
}
long long vrange(vector<long long> arr, long long l, long long r,
                 long long left, long long right) {
  long long ret;
  ret = vprevMatch(arr, l, r, right) - vprevMatch(arr, l, r, left - 1);
  return ret;
}
long long firstMarched(long long arr[], long long l, long long r, long long x) {
  long long m, ret = -1;
  while (l <= r) {
    m = (l + r) / 2;
    if (arr[m] == x) {
      ret = m;
      r = m - 1;
    } else if (arr[m] < x) {
      l = m + 1;
    } else {
      r = m - 1;
    }
  }
  return ret;
}
long long vfirstMarched(vector<long long> arr, long long l, long long r,
                        long long x) {
  long long m, ret = -1;
  while (l <= r) {
    m = (l + r) / 2;
    if (arr[m] == x) {
      ret = m;
      r = m - 1;
    } else if (arr[m] < x) {
      l = m + 1;
    } else {
      r = m - 1;
    }
  }
  return ret;
}
