#include <stdio.h>

int main() {
  int n;
  int a[100] = {0};
  int sum;
  int average;
  int odd;
  int flag = 0;
  while (scanf ("%d\n", &n) != EOF) {
    sum = 0;
    average = 0;
    odd = 0;
    flag = 0;
    for (int  i = 0 ; i < n; i++) {
      scanf ("%d ", &a[i]);
      sum += a[i];
    }
    odd = a[0] % 2;

    if (sum % n == 0) {
      average = sum / n;
      sum = 0;
      for (int j = 0; j < n; j++) {
          if (a[j] >= average) {
            sum += a[j] - average;
          } else {
            sum += average - a[j];
          }
          if (j >= 1 && (a[j] % 2) != odd) {
            flag = 1;
          }
      }
      if (flag == 1) {
        printf("-1\n");
      } else {
        printf("%d\n",sum / 4);
      }

    } else {
      printf("-1\n");
    }


  }
  return 0;
}