#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long TESTS = 1;
  while (TESTS--) {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0; i < n; i++) cin >> a[i];
    sort((a).begin(), (a).end());
    a.push_back(-1);
    long long k = 0;
    while (!a[k] && k < (long long)a.size()) k++;
    long long cnt = 1, ans = 0;
    for (long long i = k + 1; i < n + 1; i++)
      if (a[i] == a[i - 1])
        cnt++;
      else {
        if (cnt > 2) return cout << -1, 0;
        ans += cnt / 2;
        cnt = 1;
      }
    cout << ans;
  }
  return 0;
}
