#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
bool used[N];
set<int> s;
vector<int> a;
int main() {
  int n, x;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x) a.push_back(x);
  }
  int ans = 0;
  n = a.size();
  for (int i = 0; i < n; i++) {
    if (used[i]) continue;
    int f = -1;
    for (int j = i + 1; j < n && f == -1; j++)
      if (a[j] == a[i] && !used[j]) f = j;
    if (s.find(a[i]) != s.end()) {
      cout << -1;
      return 0;
    } else if (f != -1) {
      ++ans;
      used[i] = used[f] = true;
      s.insert(a[i]);
    }
  }
  cout << ans;
  return 0;
}
