#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, tmp;
  map<int, int> m;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &tmp);
    if (tmp) m[tmp]++;
  }
  int p = m.size();
  int ans = 0, fl = 0;
  ;
  for (map<int, int>::iterator iter = m.begin(); iter != m.end(); ++iter) {
    if ((*iter).second == 2) ans++;
    if ((*iter).second > 2) {
      fl = 1;
      break;
    }
  }
  if (p == 0)
    printf("%d\n", p);
  else if (fl == 1)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
