#include <bits/stdc++.h>
long long a[10000];
using namespace std;
int main() {
  long long n, i, j, c;
  cin >> n;
  for (i = 1; i < n + 1; i++) cin >> a[i];
  for (i = 1; i < n + 1; i++) {
    for (j = i + 1; j < n + 1; j++) {
      if (a[i] > a[j]) {
        c = a[i];
        a[i] = a[j];
        a[j] = c;
      }
    }
  }
  i = 1;
  while ((a[i] == 0) && (i < n + 1)) i++;
  int rez = 0;
  j = i;
  while ((a[j] != a[j + 2]) && (j < n)) {
    if (a[j] == a[j + 1]) rez++;
    j++;
  }
  if (i == n + 1)
    cout << rez;
  else {
    if (j == n)
      cout << rez;
    else
      cout << -1;
  }
  return 0;
}
