#include <bits/stdc++.h>
using namespace std;
int N;
map<int, int> m;
set<int> s;
set<int>::iterator it;
int ans;
bool can = true;
int main() {
  int i, j;
  int temp;
  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%d", &temp);
    if (temp != 0) {
      m[temp]++;
      s.insert(temp);
    }
  }
  for (it = s.begin(); it != s.end() && can; it++) {
    if (m[*it] > 2)
      can = false;
    else if (m[*it] == 2)
      ans++;
  }
  if (!can)
    printf("-1\n");
  else
    printf("%d\n", ans);
}
