#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; int main() { int n; cin >> n; vector a(n), b(n + 1, 0); for(int i = 0; i < n; i++) { cin >> a[i]; } for(int i = 0; i < n - 1; i++) { if(a[i] == a[i + 1]) { b[i + 1] = 1; } } vector c; for(int i = 0; i < n; i++) { if(b[i] == 0) { c.push_back(a[i]); } } map mp; for(int i = 0; i < c.size(); i++) { mp[c[i]]++; if(mp[c[i]] >= 3) { cout << -1 << endl; return 0; } else if(mp[c[i]] == 2 && i == c.size() - 1 && c[i] == c[0]) { cout << 1 << endl; return 0; } else if(mp[c[i]] == 2) { cout << -1 << endl; return 0; } } cout << 0 << endl; return 0; }