#include <bits/stdc++.h>
using namespace std;
int n;
map<int, int> F;
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    if (x) F[x]++;
  }
  int ans = 0;
  for (map<int, int>::iterator it = F.begin(); it != F.end(); ++it)
    if (it->first) {
      if (it->second == 2)
        ++ans;
      else if (it->second >= 3) {
        puts("-1");
        return 0;
      }
    }
  cout << ans << endl;
  return 0;
}
