#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  int array[n];
  int i, j, x;
  for (i = 0; i < n; i++) scanf("%d", &array[i]);
  for (i = 0; i < n; i++) {
    x = array[i];
    j = i - 1;
    while (j >= 0 && array[j] > x) {
      array[j + 1] = array[j];
      j--;
    }
    array[j + 1] = x;
  }
  int count1 = 0, count2 = 0, t = 1;
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      if (array[i] == array[j]) {
        if (array[i] != 0) {
          count1++;
          count2++;
          if (count2 > 1) {
            t = 0;
            count1 = -1;
            break;
          }
        }
      } else
        break;
    }
    count2 = 0;
    if (t == 0) break;
  }
  printf("%d\n", count1);
  return 0;
}
