#include using namespace std; int main(){ int N; cin >> N; vector A; for(int i=0; i> a; if(A.size() == 0 || A.back() != a) A.push_back(a); } set st; for(int a : A) st.insert(a); int ans = -1; if(st.size() == A.size()){ ans = 0; }else if(st.size()+1 == A.size() && A[0] == A.back()){ ans = 1; } cout << ans << endl; return 0; }