#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x = 0, ph = 0, np = 0;
  cin >> n;
  int arr[n];
  int arr2[n - 1];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  if (n == 2) {
    if ((arr[1] - arr[0]) % 2 == 0)
      cout << (arr[1] - arr[0]) / 2;
    else
      cout << arr[1] - arr[0];
    return 0;
  }
  for (int i = 0; i < n - 1; i++) {
    arr2[i] = arr[i + 1] - arr[i];
    if (arr2[i] > 0) {
      np++;
    }
    x = x + arr2[i];
  }
  sort(arr2, arr2 + n - 1);
  for (int i = 0; i < n - 2; i++) {
    if (arr2[i] != arr2[i + 1] && arr2[i + 1] != 0 && arr2[i] != 0) {
      ph = 1;
    }
  }
  if (ph == 1 || np > 2) {
    cout << -1 << endl;
  } else if (x == 0)
    cout << 0 << endl;
  else {
    if (np == 0)
      cout << x << endl;
    else if (np == 1 && x % 2 == 0)
      cout << x / 2 << endl;
    else
      cout << x / np << endl;
  }
  return 0;
}
