#include <bits/stdc++.h>
using namespace std;
const int oo = 2000000009;
const double eps = 1e-9;
int main() {
  int n;
  int a[1005];
  scanf("%d", &n);
  for (int i = int(0); i <= int(n - 1); i++) scanf("%d", &a[i]);
  bool f = true;
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    int count = 1;
    for (int j = i + 1; j < n; j++) {
      if (a[i] == a[j] && a[i] != 0) count++;
    }
    if (count == 2) ans++;
    if (count > 2) f = false;
  }
  if (f)
    printf("%d\n", ans);
  else
    printf("-1\n");
  return EXIT_SUCCESS;
}
