#define _GLIBCXX_DEBUG #include using namespace std; using ll=long long; using vin=vector; using vll=vector; using vvin=vector>; using vvll=vector>; using vstr=vector; using vvstr=vector>; using vch=vector; using vvch=vector>; using vbo=vector; using vvbo=vector>; using vpii=vector>; using pqsin=priority_queue,greater>; #define mp make_pair #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep2(i,s,n) for(int i=(s);i<(int)(n);i++) #define all(v) v.begin(),v.end() #define decp(n) cout<>n; vin a(n); rep(i,n)cin>>a[i]; vbo j(n+1,true); j[a[0]]=false; int prev=0; if(a[0]!=a[n-1]){ rep2(i,1,n){ if(a[i]==a[i-1]||j[a[i]])j[a[i]]=false; else{ cout<<-1<=0;i--){ if(a[i]!=a[i+1])break; r--; } rep2(i,l+1,r){ if(a[i]==a[i-1]||j[a[i]])j[a[i]]=false; else{ cout<<-1<