#include <bits/stdc++.h>
int main() {
  int n, *a;
  scanf("%d", &n);
  a = (int*)malloc(n * sizeof(int));
  int i;
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  int temp, score = 0, j;
  for (i = 0; i < n - 1; i++) {
    temp = 0;
    for (j = i + 1; j < n; j++) {
      if (a[i] == a[j] && a[i] != 0) {
        temp++;
        a[j] = 0;
      }
    }
    a[i] = 0;
    if (temp == 1)
      score++;
    else if (temp >= 2) {
      printf("-1\n");
      free(a);
      return 0;
    }
  }
  printf("%d\n", score);
  free(a);
  return 0;
}
