#include <bits/stdc++.h>
using namespace std;
const int MOD = int(1e9) + 7;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int maxn = 100001;
int a[maxn];
int main() {
  int n;
  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    if (n == 1) {
      cout << "0" << endl;
      continue;
    }
    sort(a, a + n);
    int cnt = 0, flag = 0;
    for (int i = 0; i < n;) {
      int key = a[i], id = i;
      while (id + 1 < n && a[id + 1] == key) id++;
      if (id - i == 1 && key != 0) {
        cnt++;
      } else if (id != i && id - i > 1 && key != 0) {
        flag = 1;
      }
      i = id + 1;
    }
    if (flag)
      cout << "-1" << endl;
    else
      cout << cnt << endl;
  }
  return 0;
}
