#include <bits/stdc++.h>
using namespace std;
int n, tmp, ans;
set<int> s;
vector<int> v;
map<int, int> m;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> tmp;
    m[tmp]++;
    s.insert(tmp);
  }
  while (!s.empty()) {
    v.push_back(*s.begin());
    s.erase(s.begin());
  }
  for (int i = 0; i < v.size(); ++i) {
    if (v[i] == 0) continue;
    if (m[v[i]] > 2) {
      cout << -1 << endl;
      return 0;
    }
    if (m[v[i]] == 2) ans++;
  }
  cout << ans << endl;
  return 0;
}
