#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define rep(i, n) for(int(i) = 0; (i) < (n); (i)++) #define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++) #define All(v) (v).begin(), (v).end() #define pb push_back #define MP(a, b) make_pair((a), (b)) using ll = long long; using pii = pair; using pll = pair; const int INF = 1 << 30; const ll LINF = 1LL << 60; const int MOD = 1e9 + 7; int main() { int N; cin >> N; vector A(N); rep(i, N) cin >> A[i]; vector B; int now = -1; rep(i, N) { if(now != A[i]) B.pb(A[i]); now = A[i]; } map mp; rep(i, B.size()) { mp[B[i]]++; } int ok = 2; int cnt = 0; for(auto x : mp) { if(x.second > 1) { if(cnt == 0) { ok = 1; } else { ok = 0; } cnt++; } } if(ok == 2) { cout << 0 << endl; return 0; } if(ok == 1) { if(B.front() != B.back()) ok = 0; } if(ok) { cout << 1 << endl; } else { cout << -1 << endl; } return 0; }