#include #include #include using namespace std; void ins() {} templatevoid ins(T& v,Rest&... rest){cin>>v;ins(rest...);} #define rep(i,n) for(int i=0,_i=(n);i<_i;++i) int main() { int N; ins(N); deque A; rep(i, N) { int a; cin >> a; if (A.empty() || A.back() != a) A.push_back(a); } int ans = 0; if (A.size() == 1) { cout << 0 << endl; return 0; } if (A.front() == A.back()) { ans = 1; A.pop_back(); } set s; for (const auto& e:A) { if (s.find(e) != s.end()) { cout << -1 << endl; return 0; } s.insert(e); } cout << ans << endl; return 0; }