#include <bits/stdc++.h>
using namespace std;
int N;
map<int, int> m;
map<int, int>::iterator that;
inline int nextInt();
int main() {
  N = nextInt();
  for (int(i) = 0; (i) < (int)(N); (i)++) {
    int x = nextInt();
    if (x != 0) m[x]++;
  }
  int ans = 0;
  bool mistake = false;
  for (that = m.begin(); that != m.end(); that++) {
    if (that->second > 2)
      mistake = true;
    else if (that->second == 2)
      ans++;
  }
  cout << ((mistake) ? -1 : ans) << endl;
  return 0;
}
inline int nextInt() {
  int x;
  scanf("%d", &x);
  return x;
}
