#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int count = 0;
  int id[n];
  for (int i = 0; i < n; i++) {
    cin >> id[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int subcount = 1;
    for (int j = i + 1; j < n; j++) {
      if (id[i] == 0) {
        break;
      }
      if (id[i] == id[j] && id[i] != -1) {
        subcount++;
        id[j] = -1;
      }
    }
    if (subcount == 2) {
      count++;
    } else if (subcount > 2) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << count << endl;
}
