#include <bits/stdc++.h>
using namespace std;
struct arr {
  int num;
  int x;
} b[10000];
int main() {
  int a[10000];
  int n;
  while (cin >> n) {
    memset(b, 0, sizeof(b));
    int k;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (i == 0) {
        b[i].num = 1;
        b[i].x = a[i];
        k = 1;
      } else {
        int flag1 = 0;
        for (int j = 0; j < k; j++) {
          if (b[j].x == a[i]) {
            b[j].num++;
            flag1 = 1;
          }
          if (flag1) break;
        }
        if (!flag1) {
          b[k].x = a[i];
          b[k].num = 1;
          k++;
        }
      }
    }
    int num = 0, flag = 0;
    for (int i = 0; i <= k; i++) {
      if (b[i].x == 0) continue;
      if (b[i].num == 2) num++;
      if (b[i].num >= 3) {
        flag = 1;
        break;
      }
    }
    if (flag)
      printf("-1\n");
    else
      printf("%d\n", num);
  }
  return 0;
}
