#include <bits/stdc++.h>
using namespace std;
long long n, a[11111], k = 0, s = 0;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    k = 1;
    for (int j = i + 1; j < n; j++)
      if (a[i] == a[j] && a[i]) k++;
    if (k == 2)
      s++;
    else if (k > 2) {
      cout << -1;
      return 0;
    }
  }
  cout << s;
  return 0;
}
