#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> m(n);
  for (auto&& i : m) cin >> i;
  sort(m.begin(), m.end());
  int c = 0;
  auto id = m.begin();
  for (auto i = m.begin(); i != m.end(); ++i) {
    if (*i != *id)
      id = i;
    else if (*i == 0)
      continue;
    else if (i - id == 1)
      ++c;
    else if (i - id > 1) {
      cout << -1;
      return 0;
    }
  }
  cout << c;
  return 0;
}
