#define _USE_MATH_DEFINES #include using namespace std; //template #define rep(i,a,b) for(int i=(a);i<(b);i++) #define ALL(v) (v).begin(),(v).end() typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12; templateinline bool chmax(T& a,T b){if(ainline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} //end bool ok(vector v){ set used; rep(i,0,v.size()){ if(used.count(v[i]) and v[i-1]!=v[i])return 0; used.insert(v[i]); } return 1; } int main(){ int n; scanf("%d",&n); vector a(n),cmp; rep(i,0,n){ scanf("%d",&a[i]); if(cmp.empty() or a[i]!=cmp.back())cmp.push_back(a[i]); } if(ok(cmp)){puts("0"); return 0;} rep(i,1,n){ cmp.push_back(cmp.front()); cmp.erase(cmp.begin()); if(ok(cmp)){puts("1"); return 0;} } puts("-1"); return 0; }