#include <bits/stdc++.h>
using namespace std;
int main() {
  priority_queue<int, vector<int>, greater<int> > a;
  int temp;
  int n, i;
  int sum = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &temp);
    a.push(temp);
  }
  temp = -1;
  while (!a.empty()) {
    if (a.top() == temp) {
      printf("-1\n");
      return 0;
    } else if (a.top() == 0) {
      a.pop();
    } else {
      temp = a.top();
      a.pop();
      if (!a.empty() && a.top() == temp) {
        sum++;
        a.pop();
      }
    }
  }
  printf("%d\n", sum);
  return 0;
}
