#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int *id = new int[n];
  for (int i = 0; i < n; i++) cin >> id[i];
  sort(id, id + n);
  int result = 0;
  int i = 0;
  while (i < n && id[i] == 0) i++;
  bool yes = true;
  while (i < n) {
    int j = i;
    while (j < n && id[i] == id[j]) {
      j++;
    }
    if (j == i + 2)
      result++;
    else if (j > i + 2) {
      yes = false;
      break;
    }
    i = j;
  }
  if (yes)
    cout << result;
  else
    cout << -1;
  return 0;
}
