#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int id[1000];
  pair<pair<int, int>, int> talk[1000];
  int n;
  int ans = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> id[i];
  }
  for (int i = 0; i < n; ++i) {
    if (id[i] != 0) {
      for (int j = 0; j < 1000; ++j) {
        if (talk[j].second == id[i]) {
          if (talk[j].first.second == 0) {
            talk[j].first.second = i + 1;
            ++ans;
            break;
          } else {
            cout << "-1\n";
            return 0;
          }
        }
        if (talk[j].second == 0) {
          talk[j].second = id[i];
          talk[j].first.first = i + 1;
          break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
