#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  map<int, int> o;
  vector<int> p;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    bool check = false;
    for (int j = 0; j < p.size(); j++) {
      if (a[i] == p[j]) {
        check = true;
        break;
      }
    }
    if (check == true || a[i] == 0)
      ;
    else {
      p.push_back(a[i]);
    }
    o[a[i]]++;
  }
  int counter = 0;
  for (int i = 0; i < p.size(); i++) {
    if (o[p[i]] > 2) {
      cout << -1 << endl;
      return 0;
    } else if (o[p[i]] == 2) {
      counter++;
    }
  }
  cout << counter << endl;
  return 0;
}
