/* -*- coding: utf-8 -*- * * 1053.cc: No.1053 ゲーミング棒 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; /* typedef */ /* global variables */ int as[MAX_N], used[MAX_N]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", as + i), as[i]--; n = unique(as, as + n) - as; int c = 0; for (int i = 0; i < n; i++) if (++used[as[i]] == 2) c++; printf("%d\n", (c > 1) ? -1 : c); return 0; }