#include #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, a, b) for (int i = (a); i < (b); ++i) #define PI acos(-1) #define pcnt __builtin_popcountll #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() #define sz(x) (int)(x).size() #define v(T) vector #define vv(T) v(v(T)) #define fi first #define se second using namespace std; using ll = long long; using ld = long double; using P = pair; using LP = pair; using vi = vector; using vvi = vector; using vl = vector; using vvl = vector; templateinline istream& operator>>(istream&i,v(T)&v) {rep(j,sz(v))i>>v[j];return i;} templateinline istream& operator>>(istream&i,pair&v) {return i>>v.fi>>v.se;} template inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; } ll INF = 1001001001; ll LINF = 1001001001001001001ll; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin>>n; vl as(n); cin>>as; vl ps(n + 1, -1); bool f = false; rep(i, n) { if (as[i] == as[0]) { if (f) { if (i < n - 1 && as[i] != as[i + 1]) { cout<<-1<