#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> data;
  map<int, int>::iterator p;
  int n, i, x;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    if (!x) continue;
    p = data.find(x);
    if (p == data.end()) {
      data.insert(pair<int, int>(x, 1));
    } else {
      p->second++;
    }
  }
  p = data.begin();
  n = data.size();
  x = 0;
  for (i = 0; i < n; i++) {
    if (p->second == 2)
      x++;
    else if (p->second > 2) {
      cout << -1 << endl;
      return 0;
    }
    p++;
  }
  cout << x << endl;
  return 0;
}
