#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool Up(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool Down(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
inline int getus() {
  int tmp, c;
  while (tmp = fgetc(stdin), tmp < '0' || tmp > '9')
    ;
  tmp -= '0';
  while (c = fgetc(stdin), '0' <= c && c <= '9') tmp = tmp * 10 + c - '0';
  return tmp;
}
inline int getint() {
  int tmp, c, flag;
  while (flag = fgetc(stdin), flag != '-' && (flag < '0' || flag > '9'))
    ;
  if (flag == '-')
    tmp = 0;
  else
    tmp = flag - '0';
  while (c = fgetc(stdin), '0' <= c && c <= '9') tmp = tmp * 10 + c - '0';
  return flag == '-' ? -tmp : tmp;
}
int N;
map<int, pair<int, int> > idSet;
int main() {
  int ans = 0;
  scanf("%d", &N);
  for (int i = (1); i <= (N); ++i) {
    int a;
    scanf("%d", &a);
    if (!a) continue;
    pair<int, int> &res = idSet[a];
    if (res.first == 0)
      res.first = i;
    else if (res.second == 0)
      res.second = i, ++ans;
    else {
      puts("-1");
      return 0;
    }
  }
  printf("%d\n", ans);
  return 0;
}
