#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int m = n;
  pair<int, int> p[n];
  int ct = 0;
  for (int i = 0; i < n; i++) {
    p[i].first = -1;
    p[i].second = 0;
  }
  while (m--) {
    int a;
    cin >> a;
    int flag = 0;
    if (a == 0) continue;
    for (int i = 0; i < ct; i++) {
      if (p[i].first == a) {
        p[i].second++;
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      p[ct].first = a;
      p[ct].second++;
      ct++;
    }
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (p[i].first != -1) {
      if (p[i].second == 2)
        sum++;
      else if (p[i].second > 2) {
        sum = -1;
        break;
      }
    }
  }
  cout << sum << "\n";
  return 0;
}
