#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, count = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (int i = 1; i < n - 1; i++) {
    if (a[i] == a[i - 1] && a[i] == a[i + 1] && a[i] != 0) {
      cout << -1 << endl;
      return;
    }
    if (a[i] == a[i - 1] && a[i] != 0) count++;
  }
  if (a[n - 2] == a[n - 1] && a[n - 1] != 0) count++;
  cout << count << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
