#include <bits/stdc++.h>
const int maxn = 100005;
using namespace std;
set<int> s;
int main() {
  int n, a;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    s.insert(a);
  }
  if (s.size() > 3)
    printf("-1\n");
  else {
    if (s.size() == 1) printf("0\n");
    if (s.size() == 2) {
      int d = *(++s.begin()) - *(s.begin());
      if (d % 2 == 0) d /= 2;
      printf("%d\n", d);
    }
    if (s.size() == 3) {
      int x[3];
      int j = 0;
      for (auto t = s.begin(); t != s.end(); t++) {
        x[j++] = *t;
      }
      if (2 * x[1] != x[0] + x[2])
        printf("-1\n");
      else
        printf("%d\n", x[2] - x[1]);
    }
  }
  return 0;
}
