#include <bits/stdc++.h>
int main() {
  unsigned int secretariesNumber;
  std::cin >> secretariesNumber;
  std::vector<unsigned int> secretariesSesions(secretariesNumber, 0);
  std::map<unsigned int, unsigned int> sessionIDsNumber;
  for (unsigned int secretary = 0; secretary < secretariesNumber; ++secretary) {
    std::cin >> secretariesSesions[secretary];
    sessionIDsNumber[secretariesSesions[secretary]] = 0;
  }
  unsigned int sessionsNumber = 0;
  for (unsigned int secretary = 0; secretary < secretariesNumber; ++secretary) {
    if (secretariesSesions[secretary]) {
      unsigned int current_session_members =
          ++(sessionIDsNumber[secretariesSesions[secretary]]);
      if ((current_session_members == 2) && (secretariesSesions[secretary]))
        ++sessionsNumber;
      if (current_session_members > 2) {
        std::cout << -1 << std::endl;
        return 0;
      }
    }
  }
  std::cout << sessionsNumber << std::endl;
  return 0;
}
