import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class Main{ public static void main(String[] args)throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.readLine()); String str = null; int[] num = new int[n]; int[] num1 = new int[n]; int sum = 0; int total = 0; while((str = in.readLine()) != null){ String[] s = str.split(" "); for(int i = 0;i < n;i++){ num[i] = Integer.parseInt(s[i]); } } sum = sum(num);
if(sum % n == 0){
int temp = sum / n;
for(int i = 0;i < n;i++){
num1[i] = num[i] - temp;
}
int flag = 0;
for(int i = 0;i < n;i++){
if(num1[i] % 2 != 0){
flag = 1;
System.out.println(-1);
break;
}
}
if(flag == 0){
int sum1 = 0;
for(int i = 0;i < n;i++){
if(num1[i] > 0) sum1 += num1[i];
}
total = sum1 /2;
System.out.println(total);
}
}else{
System.out.println(-1);
}
}
public static boolean isDiv(int sum,int n){
if(sum % n == 0) return true;
else return false;
}
public static int sum(int[] num){
int sum = 0;
for(int i : num){
sum += i;
}
return sum;
}
}