Arkady owns a non-decreasing array $$$a_1, a_2, \ldots, a_n$$$. You are jealous of its beauty and want to destroy this property. You have a so-called XOR-gun that you can use one or more times.In one step you can select two consecutive elements of the array, let's say $$$x$$$ and $$$y$$$, remove them from the array and insert the integer $$$x \oplus y$$$ on their place, where $$$\oplus$$$ denotes the bitwise XOR operation. Note that the length of the array decreases by one after the operation. You can't perform this operation when the length of the array reaches one.For example, if the array is $$$[2, 5, 6, 8]$$$, you can select $$$5$$$ and $$$6$$$ and replace them with $$$5 \oplus 6 = 3$$$. The array becomes $$$[2, 3, 8]$$$.You want the array no longer be non-decreasing. What is the minimum number of steps needed? If the array stays non-decreasing no matter what you do, print $$$-1$$$.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the initial length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that $$$a_i \le a_{i + 1}$$$ for all $$$1 \le i < n$$$.

Print a single integer — the minimum number of steps needed. If there is no solution, print $$$-1$$$.

NoteIn the first example you can select $$$2$$$ and $$$5$$$ and the array becomes $$$[7, 6, 8]$$$.In the second example you can only obtain arrays $$$[1, 1]$$$, $$$[3, 3]$$$ and $$$[0]$$$ which are all non-decreasing.In the third example you can select $$$1$$$ and $$$2$$$ and the array becomes $$$[3, 4, 6, 20]$$$. Then you can, for example, select $$$3$$$ and $$$4$$$ and the array becomes $$$[7, 6, 20]$$$, which is no longer non-decreasing.

#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;

#define MX 200002

void solve()
{
int n;
cin>>n;
int dp[31]={};
int arr[n];
for(int i=0;i<n;i++)
    cin>>arr[i];
for(int i=0;i<n;i++)
{
    for(int j=30;j>=0;j--)
    {
        int x=1<<j;
        if(x&arr[i])
        {
            dp[j]+=1;
            break;
        }
    }
}
for(int i=0;i<=30;i++)
{
    if(dp[i]>2)
    {
        cout<<1<<endl;
        return ;
    }
}

int ans=INT_MAX;
for(int l=1;l<=n;l++)
{
    for(int r=1;r<=n;r++)
    {
        if(l+r>n)
            break;
        for(int s=0;s<n;s++)
        {int z=0;
        if(s+l+r-1>=n)
            break;
            for(int k=s;k<s+l;k++)
                z^=arr[k];
                int c=0;
            for(int k=s+l;k<s+l+r;k++)
                c^=arr[k];
            if(c<z)
            {
                ans=min(ans,l+r-2);

            }
        }
    }
}

if(ans==INT_MAX)
    ans=-1;
cout<<ans<<endl;

}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;

while(t--)
{
solve();
}
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#define Ff(i,j,n)  for (i = j ; i < n; i++)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pll pair<long long, long long>
#define pi 3.14159265358979323846
#define trav(i,x) for(auto& i: x)
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(), x.end()
#define disp(x) for(auto& i:x){ cout << i << ' ';} cout << endl;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lb lower_bound
#define ub upper_bound

typedef vector<long long> vll;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<pll> vpll;
typedef long double ld;
typedef priority_queue <ll, vll, greater<ll>> mipq;
// F*** pointers
// Ly STL

const ll mod = 1e9+7;
const ll mod2 = 998244353;

ll binpow(ll b, ll p) { ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;}return ans;}
ll inv(ll x){return binpow(x, mod - 2);}
ll divide(ll x, ll y) {return ((x%mod)*(inv(y)))%mod;}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}

void precalc() {
    return;
}

int main()
{
    IOS
    precalc();
    ll tt, i, n;
    // cin >> tt;
    tt = 1;
    while(tt--) {
        cin >> n;
        vll v1(n, 0);
        Ff(i, 0, n)
            cin >> v1[i];

        ll j;
        ll best = n-1;

        if(n <= 2) {
            cout << -1 << '\n';
            continue;
        }

        // brute force O(n^2) :/
        ll c = v1[0]^v1[1];

        if(c > v1[2])
            best = 1;

        c = v1[n-2]^v1[n-1];

        if(c < v1[n-3])
            best = 1;

        Ff(i, 1, n-2) {
            c = v1[i]^v1[i+1];
            if(c < v1[i-1] ||c > v1[i+2]) {
                best = 1;
                break;
            }
        }

        if(best == 1) {
            cout << 1 << '\n';
            continue;
        }

        // n is small now...

        vll pref_xor(n, 0);
        pref_xor[0] = v1[0];

        Ff(i, 1, n)
            pref_xor[i] = pref_xor[i-1]^v1[i];

        ll k;

        Ff(i, 0, n-1) {
            Ff(j, i, n-1) {
                // i....j and j+1....k
                // compare xor(i....j) and xor(j+1....k)
                Ff(k, j+1, n) {
                    ll check1 = pref_xor[j];
                    if(i!=0)
                        check1 ^= pref_xor[i-1];

                    ll check2 = pref_xor[k]^pref_xor[j];

                    if(check1 > check2)
                        best = min(best, k-i-1);
                }
            }
        }

        if(best == n-1)
            cout << -1 << '\n';
        else
            cout << best << '\n';
    }
    return 0;
}

/*
4
11 22 71 92
*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int ll
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const int maxn = 1e6+9;
const ll mod = 1e9+7;
const double eps = 0.00000001;
const int inf=0x3f3f3f3f;
const ll INF = ~0ULL>>1;
const double Pi = acos(-1.0);
const int N = 2e7+9;
inline ll read() {
	char ch = getchar(); ll x= 0, f = 1;
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while ('0' <= ch && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f;
}
int n,m,p,k;
int a[maxn];
int q[maxn];
void run(){
	n=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
	}
	q[0]=0;
	q[1]=a[1];
	for(int i=2;i<=n;i++){
		q[i]=q[i-1]^a[i];
	}
	int ans=inf;
	a[0]=-inf;
	a[n+1]=inf;
	for(int i=1;i<=n;i++){
		for(int j=3;j<=34&&i+j-1<=n;j++){
			for(int k=i+1;k<=i+j-1;k++){
				int sum1=q[i-1]^q[k-1];
				int sum2=q[k-1]^q[i+j-1];
				if(sum1>sum2|sum1<a[i-1]||sum2>a[i+j]){
					ans=min(max((ll)1,j-2),ans);
				}
			}

		}
	}
	if(ans==inf) puts("-1");
	else  printf("%lld\n",ans);
}
signed main(){
	int _T=1;
//	 _T=read();
	while(_T--){
		run();
	}

}

#include <bits/stdc++.h>
#define N 100010
#define ll long long
#define Re register
#define mo ((int)1e9+7)
#define squ(x) ((x)*(x))
#define db double
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define rep(i,l,r) for(Re int i=l;i<=r;++i)
#define drep(i,r,l)for(Re int i=r;i>=l;--i)
#define pb push_back
using namespace std;

inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') {if (ch == '-')f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	return x * f;
}
int a[N], b[N], s[N], cnt[N];
int f(int x) {
	int res = 0;
	for (; x; x >>= 1, ++res);
	return res;
}
int main() {
	int n = read();
	rep(i, 1, n) {
		a[i] = read();
		++cnt[b[i] = f(a[i])];
	}
	rep(i, 1, 31)if (cnt[i] > 2) {puts("1"); return 0;}
	int ans = n;
	rep(i, 1, n)s[i] = s[i - 1] ^ a[i];
	rep(l, 1, n - 1)rep(r, l + 1, n)rep(mid, l, r - 1)
	if ((s[mid]^s[l - 1]) > (s[r]^s[mid]))cmin(ans, r - l - 1);
	printf("%d\n", ans == n ? -1 : ans);
	return 0;
}

//HEADER FILES AND NAMESPACES

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

// DEFINE STATEMENTS
const long long infty = 1e18;
#define num1 1000000007
#define num2 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define REPd(i,a,n) for(ll i=a; i>=n; i--)
#define pb push_back
#define pob pop_back
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.000000001)

typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpll;
typedef vector<int> vii;

// DEBUG FUNCTIONS
#ifndef ONLINE_JUDGE

template<typename T>
void __p(T a) {
	cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
	cout<<"{";
	__p(a.first);
	cout<<",";
	__p(a.second);
	cout<<"}";
}
template<typename T>
void __p(std::vector<T> a) {
	cout<<"{";
	for(auto it=a.begin(); it<a.end(); it++)
		__p(*it),cout<<",}"[it+1==a.end()];
}
template<typename T>
void __p(std::set<T> a) {
	cout<<"{";
	for(auto it=a.begin(); it!=a.end();){
		__p(*it);
		cout<<",}"[++it==a.end()];
	}

}
template<typename T>
void __p(std::multiset<T> a) {
	cout<<"{";
	for(auto it=a.begin(); it!=a.end();){
		__p(*it);
		cout<<",}"[++it==a.end()];
	}
}
template<typename T, typename F>
void __p(std::map<T,F> a) {
	cout<<"{\n";
	for(auto it=a.begin(); it!=a.end();++it)
	{
		__p(it->first);
		cout << ": ";
		__p(it->second);
		cout<<"\n";
	}
	cout << "}\n";
}

template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
	__p(a1);
	__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";
	__p(arg1);
	cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(;; i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	const char *comma=names+i;
	cout.write(names,comma-names)<<" : ";
	__p(arg1);
	cout<<" | ";
	__f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#define error(...)
#endif

// DEBUG FUNCTIONS END

// CUSTOM HASH TO SPEED UP UNORDERED MAP AND TO AVOID FORCED CLASHES
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());  // FOR RANDOM NUMBER GENERATION

ll mod_expected(ll a, ll b, ll c)
{
	ll res=1;   a=a%c;
	while(b>0)
	{
		if(b%2==1)
			res=(res*a)%c;
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll mymod(ll a,ll b)
{
		return ((a%b)+b)%b;
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m)
{
		ll x, y;
		ll g = gcdExtended(a, m, &x, &y);
		g++;   //this line was added just to remove compiler warning
		ll res = (x%m + m) % m;
		return res;
}
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
		if (a == 0)
		{
				*x = 0, *y = 1;
				return b;
		}
		ll x1, y1;
		ll gcd = gcdExtended(b%a, a, &x1, &y1);
		*x = y1 - (b/a) * x1;
		*y = x1;
		return gcd;
}

struct node
{
	vll adj;
};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	vll A(n);
	REP(i, 0, n)
	{
		cin >> A[i];
	}
	if(n>100) {cout << "1\n"; exit(0);}
	ll ans = LLONG_MAX;
	REP(i, 0, n)
	{
		ll xo = A[i];
		REP(j, 1, 100)
		{
			if(i+j>=n) break;
			xo ^= A[i+j];
			if(i>0 && xo<A[i-1]) {ans = min(ans, j); break; }
			if(i+j<n-1 && xo>A[i+j+1]) {ans = min(ans, j); break; }
		}
	}
	REP(i, 0, n-1)
	{
		ll prex = A[i];
		REP(j, 1, i+1)
		{
			prex^=A[i-j];
			ll sufx = A[i+1];
			REP(k, 1, n-i-1)
			{
				sufx^=A[i+1+k];
				if(prex > sufx)
				{
					ans = min(ans, k+j);
				}
			}
		}
	}
	cout << (ans == LLONG_MAX ? -1 : ans) << "\n";
	return 0;
}

/*
1. Check borderline constraints. Can a variable you are dividing by be 0?
2. Use ll while using bitshifts
3. Do not erase from set while iterating it
4. Initialise everything
5. Read the task carefully, is something unique, sorted, adjacent, guaranteed??
6. DO NOT use if(!mp[x]) if you want to iterate the map later
7. Are you using i in all loops? Are the i's conflicting?
*/

#include<bits/stdc++.h>
#define int long long
using namespace std;
template<typename T>inline void read(T &x){
	x=0;int f=1;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	x*=f;
}
template<typename T>inline void write(T x){
	if(x<0){putchar('-');x=-x;}
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
template<typename T>inline void writeln(T x){
	write(x);
	puts("");
}
template<typename T>inline void writex(T x){
	write(x);
	putchar(' ');
}
int a[100010],h[35];
int b[100010];
int lowbit(int x){return x&(-x);}
signed main(){
	int n;read(n);
	if(n>100){
	cout<<1;return 0;
	}
	for(int i=1;i<=n;i++){
		read(a[i]);
		int x=a[i];
		while(a[i]-lowbit(a[i]))a[i]-=lowbit(a[i]);
		for(int i=0;i<=31;i++)
			if(a[i]==(1<<i))h[i]++;
		a[i]=x;
	}
	for(int i=1;i<=n;i++)b[i]=b[i-1]^a[i];
	int ans=INT_MAX;
	for(int i=1;i<=n;i++)
	{
		for(int j=i;j<=n;j++)
		{
			for(int k=j+1;k<=n;k++)
			{
				if((b[i-1]^b[j])>(b[j]^b[k]))
				{
					ans=min(ans,k-i-1);
				}
			}
		}
	}
	if(ans==INT_MAX)puts("-1");else cout<<ans<<endl;
	return 0;
}

#include<bits/stdc++.h>
#ifdef LOCAL
#include<ctime>
#include<windows.h>
#include<random>
#include"file.h"
#define __int128 LL
#endif

#define y1 zyy_orz
#define hash sto_zyy

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL>pLL;
typedef pair<int, int>pii;
const double eps = 1e-10;
const double PI = 3.1415926535897932;
const int dir[4][2] = { -1,0,0,-1,1,0,0,1 };
//const int dir[8][2] = { -1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1 };
//const int dir[8][2] = { -2,-1,-2,1,2,-1,2,1,-1,2,-1,-2,1,2,1,-2 };

const int maxn = 1e7 + 5;
int trie[maxn][2];
int n;
int w[maxn];
int base = 30;

int pre[maxn];
int suf[maxn];
int s[maxn];
int pn;

void insert(int x){
	int p = 1;
	for (int i = base; i >= 0; i--) {
		int idx = (x >> base & 1);
		if (!trie[p][idx])trie[p][idx] = ++pn;
		p = trie[p][idx];
	}
}

int main() {
#ifdef LOCAL
	fileopen();
#endif
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)scanf("%d", &w[i]), s[i] = s[i - 1] ^ w[i];

	int ans = 1e9;
	for (int i = 1; i <= n; i++) {
		int a = i, b = i + 1;
		for (int j = max(a - 31, 1); j <= a; j++) {
			for (int k = b; k <= min(b + 31, n); k++) {
				int u = s[a] ^ s[j - 1];
				int v = s[k] ^ s[b - 1];
				if (u > v)
					ans = min(ans, k - j - 1);
			}
		}
	}
	if (ans > 1e8)ans = -1;
	printf("%d\n", ans);

#ifdef LOCAL
	fileclose();
#endif
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<ll>vec;

int main()
{
    ll a,b,c,d,e,i,j,k,l,n,m,x,y,t,p;
    scanf("%lld",&n);
    for(i=0; i<n; i++)
    {
        scanf("%lld",&a);
        vec.push_back(a);
    }
    if(n>=100)
    {
        printf("1\n");
        return 0;
    }
    x=2*n;
    for(i=0;i<n;i++)
    {
        a=vec[i];
        for(j=i+1;j<n;j++)
        {
            a=a^vec[j];
            c=j-i;
            y=2*n;
            d=0;
            b=0;
            for(k=i-1;k>=0;k--)
            {
                b=b^vec[k];
                if(b>a)
                {
                    d=(i-1)-k;
                    y=min(y,c+d);
                }
            }

            b=0;
            for(k=j+1;k<n;k++)
            {
                b=b^vec[k];
                if(b<a)
                {
                    d=k-(j+1);
                    y=min(y,c+d);
                }
            }
            x=min(x,y);
        }
    }
    if(x==2*n)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<x<<endl;
    }
}

//#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
#define mst(a,x) memset(a,x,sizeof(a))
#define fi first
#define se second
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
//int cansel_sync=(ios::sync_with_stdio(0),cin.tie(0),0);
const int N=200010; typedef long long ll; const int inf=~0u>>2; const ll INF=~0ull>>2; ll read(){ll x; if(scanf("%lld",&x)!=1)exit(0); return x;} typedef double lf; const lf pi=acos(-1.0); lf readf(){lf x; if(scanf("%lf",&x)!=1)exit(0); return x;} typedef pair<ll,ll> pii; template<typename T> void operator<<(vector<T> &a,T b){a.push_back(b);}
const ll mod=(1?1000000007:998244353); ll mul(ll a,ll b,ll m=mod){return a*b%m;} ll qpow(ll a,ll b,ll m=mod){ll ans=1; for(;b;a=mul(a,a,m),b>>=1)if(b&1)ans=mul(ans,a,m); return ans;}
//#define int ll
#define clz __builtin_clz
#define ok(x) {cout<<x<<endl; return;}
int a[N],s[N];
void Solve(){
	int n=read();
	repeat(i,0,n)a[i]=read();
	repeat(i,0,n-2){
		if(clz(a[i])==clz(a[i+1]) && clz(a[i])==clz(a[i+2]))
			ok(1);
	}
	int ans=inf;
	repeat_back(i,0,n)s[i]=s[i+1]^a[i];
	repeat(l,0,n)
	repeat(r,l,n+1)
	repeat(m,l+1,r){
		if((s[m]^s[l])>(s[m]^s[r]))
			ans=min(ans,r-l-2);
	}
	cout<<(ans==inf?-1:ans)<<endl;
}
signed main(){
	//freopen("data.txt","r",stdin);
	int T=1; //T=read();
	repeat(ca,1,T+1){
		Solve();
	}
	return 0;
}

#pragma GCC optimize("O3")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl '\n'
#define TIME 1.0*clock()/CLOCKS_PER_SEC
#define int ll
#define pii pair <int, int>

using namespace std;
//using namespace __gnu_pbds;

const ll N = 2e4 + 13;
const ll M = 2e7 + 13;
const ll mod = 1000000007;
const int rx[] = {-1, +1, 0, 0};
const int ry[] = {0, 0, -1, +1};
const ld eps = 0.00001;
const int inf = 1e18;

mt19937 gen(time(0));

//typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("flight.in", "r", stdin);
//    freopen("flight.out", "w", stdout);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // LOCAL

    int n;
    cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; ++i){
        cin >> a[i];
    }
    if (n > 60){
        cout << 1;
        return 0;
    }
    vector <int> pr(n, 0);
    pr[0] = a[0];
    for (int i = 1; i < n; ++i){
        pr[i] = (pr[i - 1] ^ a[i]);
    }
    int ans = inf;
    for (int l1 = 0; l1 < n - 1; ++l1){
        for (int r1 = l1; r1 < n - 1; ++r1){
            int l2 = r1 + 1;
            for (int r2 = l2; r2 < n; ++r2){
//                cerr << l1 << " " << r1 << " " << l2 << " " << r2 << endl;
                int xor1 = pr[r1];
                if (l1) xor1 = (xor1 ^ pr[l1 - 1]);
                int xor2 = (pr[r2] ^ pr[l2 - 1]);
                if (xor1 > xor2){
                    ans = min(ans, r1 - l1 + r2 - l2);
                }
            }
        }
    }
    if (ans == inf) ans = -1;
    cout << ans;

    return 0;
}

#include <bits/stdc++.h>

#define int long long
#define all(x) x.begin(), x.end()

using namespace std;

int max_bit(int n) {
    int cnt = 0;
    while (n > 0) {
        cnt++;
        n /= 2;
    }
    return cnt;
}

void sol() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int &el : a) {
        cin >> el;
    }
    for (int i = 0; i < n - 1; i++) {
        int now = a[i] ^a[i + 1];
        if (i > 0) {
            if (a[i - 1] > now) {
                cout << 1 << '\n';
                return;
            }
        }
        if (i < n - 2) {
            if (a[i + 2] < now) {
                cout << 1 << '\n';
                return;
            }
        }
    }
    int ans = (int) 1e15;
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            for (int c = j + 1; c < n; c++) {
                int now1 = 0, now2 = 0;
                for (int k = i; k <= j; k++) {
                    now1 ^= a[k];
                }
                for (int k = j + 1; k <= c; k++) {
                    now2 ^= a[k];
                }
                if (now1 > now2) {
                    int kek = (j - i) + (c - (j + 1));
                    ans = min(ans, kek);
                }
            }
        }
    }
    cout << (ans == (int) 1e15 ? -1 : ans) << '\n';
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
//    cin >> t;
    while (t--) {
        sol();
    }
}

#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <deque>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector<int> a(n + 2);
	for (int i = 0; i < n; i++) {
		cin >> a[i + 1];
	}
	a[0] = -1;
	a[n + 1] = (1 << 30);
	if (n > 70) {
		cout << 1;
		return 0;
	}
	int ans = 1e9;
	for (int i = 0; i <= n; i++) {
		int nw1 = 0; int nw2 = 0;
		for (int j = i; j >= 0; j--) {
			nw1 ^= a[j];
			nw2 = 0;
			for (int u = i + 1; u <= n + 1; u++) {
				nw2 ^= a[u];
				if (nw1 > nw2) {
					ans = min(ans, u - j - 1);
				}
			}
		}
	}
	if (ans == 1e9) {
		cout << -1;
	}
	else {
		cout << ans;
	}
}
//-1 1 2 5 6 8 100

#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pi pair<int,int>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pi, null_type,less<pi>, rb_tree_tag,tree_order_statistics_node_update>

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>
#define pi3 pair<int, pi>
#define p4 pair<int, pi3>

const int MX=200000+10;
const ll mod=998244353;

ll a[MX];

int main()
{
    FasterIO;

    int n; cin>>n;

    ll xr=0;
    for(int i=1; i<=n; xr^=a[i], i++) cin>>a[i];

    if(n==2 || n==3 && xr==0) cout<<-1<<'\n';
    else
    {
        int mx=n, flg=0;
        for(int i=1; i<n; i++)
        {
            ll xr=0;
            for(int j=i; j>=max(i-30, 1) && (i-j)<mx; j--)
            {
                xr^=a[j];
                ll xr2=0;
                for(int k=i+1; k<=min(n, k+30) && (k-j-1)<mx; k++)
                {
                    xr2^=a[k];
                    if(xr>xr2) mx=min(mx, i+k-(i+j+1)), flg=1;
                }
            }
        }

        if(flg) cout<<mx<<'\n';
        else    cout<<-1<<'\n';
    }
    return 0;
}

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=100;
typedef long long LL;
LL a[maxn];
LL sum[maxn];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n;cin>>n;
  if(n>60){
    cout<<"1"<<endl;
    return 0;
  }
  a[n+1]=1e18;
  for(LL i=1;i<=n;i++) cin>>a[i];
  for(LL i=1;i<=n;i++){
    sum[i]=sum[i-1]^a[i];
  }
  LL res=1e18;
  for(LL l=1;l<=n;l++){
    for(LL r=l+1;r<=n;r++){
        LL t=sum[r]^sum[l-1];
        if(t>a[r+1]||t<a[l-1]){
            res=min(res,r-l+1-1);
          ///  debug(res);
        }
    }
  }
  for(LL i=1;i<=n;i++){///[i,j][j+1,k]
    for(LL j=i+1;j<=n;j++){
        for(LL k=j+1;k<=n;k++){
            LL t1=sum[j]^sum[i-1];
            LL t2=sum[k]^sum[j];
            if(t1>t2){
                res=min(res,k-j+1-1+j-i+1-1-1);
            }
        }
    }
  }
  if(res==1e18){
    cout<<"-1"<<endl;
  }
  else cout<<res<<endl;
return 0;
}

#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

const int64_t inf = 1000000000012LL;

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;
	vector <int64_t> a(n + 2, 0);
	a[n + 1] = inf;
	for (int i = 1; i <= n; ++i)
		cin >> a[i];
	if (n >= 93)
		cout << "1\n";
	else {
		int64_t ans = inf;
		for (int l = 1; l + 1 <= n; ++l) {
			for (int len1 = 1; l + len1 <= n; ++len1) {
				for (int len2 = 1; l + len1 + len2 + 1 <= n; ++len2) {
					int64_t t1 = 0, t2 = 0;
					for (int i = l; i <= l + len1; ++i)
						t1 ^= a[i];
					for (int i = l + len1 + 1; i <= l + len1 + len2 + 1; ++i)
						t2 ^= a[i];
					if (a[l - 1] > t1 || t1 > t2)
						ans = min(ans, int64_t(len1 + len2));
				}
			}
		}
		for (int l = 1; l + 1 <= n; ++l) {
			for (int len1 = 1; l + len1 <= n; ++len1) {
				int t = 0;
				for (int i = l; i <= l + len1; ++i)
					t ^= a[i];
				if (a[l - 1] > t || t > a[l + len1 + 1])
					ans = min(ans, int64_t(len1));
			}
		}
		cout << (ans == inf ? -1: ans) << '\n';
	}
}

#include<iostream>
#include<cstdio>
using namespace std;
inline int read()
{
	int n=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		n=n*10+ch-'0';
		ch=getchar();
	}
	return n*f;
}
int a[200005];
int main()
{
	int n,ans=1000000000;
	n=read();
	for(int i=1;i<=n;i++)a[i]=read()^a[i-1];
	if(n>=100)
	{
		printf("1\n");
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=i-1;j++)
		{
			for(int k=i;k<=n;k++)
			{
				if((a[i-1]^a[j-1])>(a[i-1]^a[k]))
				{
					ans=min(ans,k-j-1);
				}
			}
		}
	}
	if(ans!=1000000000)printf("%d\n",ans);
	else printf("-1\n");
	return 0;
}

//Author : Vivek Dubey
#include <bits/stdc++.h>
using namespace std;

// debug start
	template <typename A, typename B>
	string to_string(pair<A, B> p);

	template <typename A, typename B, typename C>
	string to_string(tuple<A, B, C> p);

	template <typename A, typename B, typename C, typename D>
	string to_string(tuple<A, B, C, D> p);

	string to_string(const string& s) {
	  return '"' + s + '"';
	}

	string to_string(const char* s) {
	  return to_string((string) s);
	}

	string to_string(bool b) {
	  return (b ? "true" : "false");
	}

	string to_string(vector<bool> v) {
	  bool first = true;
	  string res = "{";
	  for (int i = 0; i < static_cast<int>(v.size()); i++) {
	    if (!first) {
	      res += ", ";
	    }
	    first = false;
	    res += to_string(v[i]);
	  }
	  res += "}";
	  return res;
	}

	template <size_t N>
	string to_string(bitset<N> v) {
	  string res = "";
	  for (size_t i = 0; i < N; i++) {
	    res += static_cast<char>('0' + v[i]);
	  }
	  return res;
	}

	template <typename A>
	string to_string(A v) {
	  bool first = true;
	  string res = "{";
	  for (const auto &x : v) {
	    if (!first) {
	      res += ", ";
	    }
	    first = false;
	    res += to_string(x);
	  }
	  res += "}";
	  return res;
	}

	template <typename A, typename B>
	string to_string(pair<A, B> p) {
	  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
	}

	template <typename A, typename B, typename C>
	string to_string(tuple<A, B, C> p) {
	  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
	}

	template <typename A, typename B, typename C, typename D>
	string to_string(tuple<A, B, C, D> p) {
	  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
	}

	void debug_out() { cerr << endl; }

	template <typename Head, typename... Tail>
	void debug_out(Head H, Tail... T) {
	  cerr << " " << to_string(H);
	  debug_out(T...);
	}

	#ifndef ONLINE_JUDGE
	#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
	#else
	#define debug(...) 42
	#endif
// end debug

	#define int long long

const int mxN = 3e5 + 1;

int n;
int a[mxN];

void solve() {
	cin >> n;

	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}

	if(n >= 64) {
		cout << 1;
		return;
	}

	int cost = -1;

	for(int i = 0; i < n - 1; i++) {
		int x = 0;
		// backward, forward
		for(int p = i; p >= 0; p--) {
			x ^= a[p];
			int y = 0;
			for(int q = i + 1; q < n; q++) {
				// debug(x, y, p, q);
				y ^= a[q];
				if(x > y) {

					if(cost == -1) {
						cost = q - p - 1;
					}
					cost = min(cost, q - p - 1);
				}

			}
		}
	}

	cout << cost;
}

int32_t main() {
	#ifndef ONLINE_JUDGE
	    // for getting input from input.txt
		freopen("input.txt", "r", stdin);
	    // for writing output to output.txt
	    //this can be opted out if you want to print the output to the sublime console
		freopen("output.txt", "w", stdout);
	#endif

	// for fast i/o
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	// test cases
	int t = 1;
	// cin >> t;
	while(t--) {
		solve();
	}

	return 0;
}

#include <bits/stdc++.h>
#ifdef LOCAL
#include "debuger.hpp"
#else
#define DUMP(...) 1145141919810
#define CHECK(...) (__VA_ARGS__)
#endif

const int INF = 0x3f3f3f3f;
const int kN = 100000 + 5;
int n;
int a[kN];
int s[kN];

int highestbit(int x) {
  for (int i = 0; ; ++i) {
    if ((x >> i) == 1) return i;
  }
}

int solve() {
  for (int i = 1; i + 2 <= n; ++i) if (a[i] > 0) {
    int q = highestbit(a[i]);
    int w = highestbit(a[i + 1]);
    int e = highestbit(a[i + 2]);
    if (q == w && w == e) return 1;
  }
  for (int i = 1; i <= n; ++i) {
    s[i] = a[i] ^ s[i - 1];
  }
  int ret = INF;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < i; ++j) {
      for (int k = i + 1; k <= n; ++k) {
        if ((s[j] ^ s[i]) > (s[k] ^ s[i])) {
          ret = std::min(ret, i - j - 1 + k - i - 1);
        }
      }
    }
  }
  return ret == INF ? -1 : ret;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  printf("%d\n", solve());
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define len(a) ll((a).size())
#define pb push_back
#define pw(a) (1LL << (a))
#define y1 CNik
#define m_p make_pair
#define int ll

using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;

const ll INF = ll(2e18);
const int N = int(2e6);
const ll mod = ll(998244353);

template <typename T> using o_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

ll n, a[N], x, pos, mn, mx, ans = INF, c, c1;
vector <ll> v[N];
signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i]; x = a[i];
        while(x) {
            v[i].pb(x % 2);
            x /= 2;
        }
    }
    for(int i = 0; i < n; i++) {
        pos = i;
        while(pos < n && len(v[pos]) == len(v[i])) pos++;
        if(pos - i >= 3) {
            return cout << 1 << '\n', 0;
        }
        i = pos - 1;
    }
    for(int i = 0; i < n; i++) {
        c = 0;
        for(int j = i; j < n; j++) {
            c ^= a[j];
            if(i == 0) mx = -INF;
            else mx = a[i - 1];
            if(j == n - 1) mn = INF;
            else mn = a[j + 1];
            if(c > mn || c < mx) ans = min(ans, j - i + 1);
        }
    }
    for(int i = 0; i < n; i++) {
        c = 0;
        for(int j = i; j < n; j++) {
            c ^= a[j];
            for(int ii = j + 1; ii < n; ii++) {
                c1 = 0;
                for(int jj = ii; jj < n; jj++) {
                    c1 ^= a[jj];
                    if(c1 < c) ans = min(ans, j - i + 1 + jj - ii);
                }
            }
        }
    }
    if(ans == INF) cout << -1 << '\n';
    else cout << ans - 1 << '\n';
}

#include<bits/stdc++.h>
using namespace std;
#define re register int
#define F(x,y,z) for(re x=y;x<=z;x++)
#define FOR(x,y,z) for(re x=y;x>=z;x--)
typedef long long ll;
#define I inline void
#define IN inline int
#define C(x,y) memset(x,y,sizeof(x))
#define STS system("pause")
template<class D>I read(D &res){
	res=0;register D g=1;register char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')g=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		res=(res<<3)+(res<<1)+(ch^48);
		ch=getchar();
	}
	res*=g;
}
int n,m,a[101000],b[101000],s[101000],ans;
int main(){
	read(n);ans=n;
	F(i,1,n)read(a[i]);
	F(i,1,n){
		m=a[i];while(m)b[i]++,m>>=1;
	}
	F(i,1,n-1)if(a[i]>a[i+1])return printf("0"),0;
	F(i,2,n-1)if(b[i]==b[i-1]&&b[i]==b[i+1])return printf("1"),0;
	F(i,1,n)s[i]=s[i-1]^a[i];
	F(i,1,n-1)F(j,i,n-1)F(k,j+1,n)if((s[j]^s[i-1])>(s[k]^s[j]))ans=min(ans,k-i-1);
	if(ans==n)ans=-1;
	printf("%d",ans);
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define lli long long int
#define vi vector<int>
#define vlli vector<long long int>
#define pii pair<int, int>
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define repa(i, a, b) for(int i = (a); i >= (b); i--)
#define repv(x, v) for(auto x : v)
#define debug(x) cout << #x << " = " << x << endl
#define debugsl(x) cout << #x << " = " << x << ", "
#define debugarr(x, a, b) cout << #x << " = ["; rep(i, a, b) cout << x[i] << ", "; cout << "]\n"
#define pb push_back

lli n, a[200003], x, y, res;

int main()
{
    fastio;

    cin >> n;
    rep(i, 1, n) cin >> a[i];
    a[0] = 0;
    a[n + 1] = (1ll << 32);

    if (n > 60){
        cout << "1\n";
        return 0;
    }

    res = n + 1;
    rep(i, 1, n){
        x = 0;
        repa(j, i, 1){
            x ^= a[j];
            y = 0;
            rep(k, i + 1, n){
                y ^= a[k];
                if (y < x){
                    res = min(res, k - j - 1ll);
                }
            }
        }
    }

    if (res == n + 1) cout << "-1\n";
    else cout << res << "\n";

    return 0;
}

#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <cassert>
#include <string.h>
#include <random>
#include <chrono>
#include <ext/rope>

#define sqr(x) ((x) * (x))

using ll = long long;
using ld = long double;
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template <class T>
using indexed_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
void fastIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
}
mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());

int n;

signed main() {
    fastIO();

    cin >> n;
    vector <ll> a(n);
    for (auto &i: a) {
        cin >> i;
    }

    if (n >= 65) {
        cout << 1;
        return 0;
    }

    vector <ll> pref_xor(n);
    pref_xor[0] = a[0];
    for (int i = 1; i < n; ++i) {
        pref_xor[i] = (pref_xor[i - 1] ^ a[i]);
    }

    int ans = 70;
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            for (int k = j + 1; k < n; ++k) {
                int pref_j = pref_xor[j], pref_seg = pref_xor[j] ^ pref_xor[k];

                if (i > 0) {
                    pref_j ^= pref_xor[i - 1];
                }
                if (pref_j > pref_seg) {
                    ans = min(ans, k - i - 1);
                }
            }
        }
    }

    cout << (ans < 70 ? ans : -1);

    return 0;
}

#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include <map>
#include <string>
#include <algorithm>
#include <iomanip>
#include <set>
#include <unordered_set>
#include <deque>
#include <functional>
#include <queue>
#include <cmath>
#include <array>

#define int long long
//#define endl '\n'
using namespace std;

const int INF = 1e18;
int a, b, c, d, e, p = 1e9 + 7, q, t, f;
int debug = 0;
string s;
set<pair<int, int>> set1;
int mas[200000];
int gcd(int a, int b) {
	while (a && b) {
		if (a > b) {
			a %= b;
		}
		else {
			b %= a;
		}
	}
	return a + b;
}
map<int, vector<int>> mp;
vector<int> vec, vec2, vec3, vec4;

const int MAXN = 3e5;
int arr[MAXN];
int lft[MAXN], rgh[MAXN];
int used[MAXN];

signed main() {
	ios_base::sync_with_stdio(false);
	srand(5757);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	if (n > 120) {
		cout << 1;
		return 0;
	}
	int res = INF;
	for (int i = 0; i < n; i++) {
		for (int j = i; j < n; j++) {
			for (int i2 = j + 1; i2 < n; i2++) {
				int ans1 = 0, ans2 = 0;
				for (int k = i; k <= j; k++) {
					ans1 = (ans1 ^ arr[k]);
				}
				for (int k = j + 1; k <= i2; k++) {
					ans2 = (ans2 ^ arr[k]);
				}
				if (ans1 > ans2) {
					res = min(res, i2 - i - 1);
				}
			}
		}
	}
	if (res > 1e9) {
		cout << -1;
		return 0;
	}
	cout << res;
	cin >> a;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(0);
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	map<int, int> level, index;
	bool three = false;
	for (int i = n-1; i >= 0; i--) {
		int zero = __builtin_clz(a[i]);
		if (!index.count(zero))
			index[zero] = i;
		level[zero]++;
		if (level[zero] == 3) {
			three = true;
			break;
		}
	}
	if (three) {
		cout << 1 << '\n';
		return 0;
	}
	int before = -1;
	int step = 0;
	int ans = n;
	for (auto& p: index) {
		int zero = p.first;
		int i = p.second;
		step++;
		int first, second, pre;
		if (before == -1 || __builtin_clz(before) < zero) {
			if (level[zero] == 1) {
				before = -1;
				step = 0;
				continue;
			}
			first = a[i];
			second = a[i-1];
			pre = i - 2;
		} else {
			if (level[zero] == 2) {
				ans = min(ans, step);
				before = -1;
				step = 1;
				first = a[i];
				second = a[i-1];
				pre = i - 2;
			} else {
				first = before;
				second = a[i];
				pre = i - 1;
			}
		}
		int high = first ^ second;
		if (pre >= 0) {
			int low = second ^ a[pre];
			if (high < a[pre] || low > first) {
				ans = min(ans, step);
				before = -1;
				step = 0;
			} else
				before = high;
		}
	}
	if (ans == n)
		cout << -1 << '\n';
	else
		cout << ans << '\n';
	return 0;
}

//;)
#include <bits/stdc++.h>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define form(i,a,b) for (int i=a;i>=b;i--)
#define forp(i,a,n) for (int i=a;i<n;i++)
#define forn(i,n) for (int i=0;i<n;i++)
#define fast cin.tie(0);cout.tie(0);std::ios_base::sync_with_stdio(0);
#define str string
#define pb push_back
#define oh cout<<"HERE"<<endl;
#define sz size
#define fr freopen("pails.in","r",stdin);freopen("pails.txt","w",stdout);
#define f first
#define s second
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define endl '\n'
#define ok return 0;
#define one cout<<"Alice"<<endl;
#define two cout<<"Bob"<<endl;

typedef long long ll;
typedef long double ld;
typedef vector<pair<int,int>> vp;

const ll t_max=1e9+7;
const ll MAXX=ll(1e18);
const int INF=int(-1e9);
const double PI=3.1415926535;

void read() {}
template<typename T1> void read(T1 v[],int n)
{
    forn(i,n) cin>>v[i];
}
template<typename T2> void read(vector<T2>& v,int n)
{
    forn(i,v.sz()) cin>>v[i];
}
template<typename First, typename... Rest> void read(First& first,Rest&... rest)
{
    cin>>first;
    read(rest...);
}
template<typename T3> void print(vector<T3>& v,int n)
{
    forn(i,v.sz()) cout<<v[i]<<endl;
}
template<typename T4> void print(T4 v[],int n)
{
    forn(i,n) cout<<v[i]<<endl;
}

ll binpow (ll a, ll n, ll k)
{
    ll res=1;
    while (n)
        if (n&1)
        {
            res*=a;
            res%=k;
            n--;
        }
        else
        {
            a*=a;
            a%=k;
            n>>=1;
        }
    return res;
}

bool solve()
{
    int n,ans=1e6;
    cin>>n;
    int mas[n];
    read(mas,n);
    for(int i=1;i<n-1;i++)
    {
        if((mas[i]^mas[i+1])<mas[i-1]) ans=1;
    }
    for(int i=0;i<n-2;i++)
    {
        if((mas[i]^mas[i+1])>mas[i+2]) ans=1;
    }
    if(ans==1)
    {
        cout<<1<<endl;
        return 0;
    }
    for(int i=0;i<n-1;i++)
    {
        int s=0;
        for(int j=i+1;j<n;j++)
        {
            s=(s^mas[j]);
            if(s<mas[i]&&j-i>1) ans=min(ans,j-i-1);
        }
    }
    for(int i=1;i<n;i++)
    {
        int s=0;
        for(int j=i-1;j>=0;j--)
        {
            s=(s^mas[j]);
            if(s>mas[i]&&i-j>1) ans=min(ans,i-j-1);
        }
    }
    for(int i=0;i<n;i++)
    {
        int s1=0;
        for(int j=i;j>=0;j--)
        {
            s1=(s1^mas[j]);
            int s2=0;
            for(int k=i+1;k<n;k++)
            {
                s2=(s2^mas[k]);
                if(s1>s2)
                {
                    ans=min(ans,k-j-1);
                }
            }
        }
    }
    if(ans==1e6) cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;
}

int main()
{
    //fast
    int t=1;
    //cin>>t;
    forn(i,t)
    {
        solve();
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int n,Ans;

int A[100005];

inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){
       if(ch=='-')f=-1;
       ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
       x=(x<<1)+(x<<3)+ch-'0';
       ch=getchar();
    }
    return x*f;
}

int main(){

    n=read();

    for(register int i=1;i<=n;++i)
        A[i]=A[i-1]^read();

    if(n>60){
        printf("%d\n",1);
        return 0;
    }

	Ans=n;

	for(register int i=1;i<=n;++i)
	for(register int j=i;j<=n;++j)
	for(register int k=n;k> j;--k){
		if((A[i-1]^A[j])>(A[k]^A[j]))
			Ans=min(Ans,k-i-1);
	}

    printf("%d\n",Ans==n?-1:Ans);

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define fori(i,a,n) for(i=a;i<=n;i++)
#define ford(i,n,a) for(i=n;i>=a;i--)
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
const int N=2e5+5;
const int inf=20000000;
int n,i,a[N],w1,w2,ans,j,k;
int main()
{
	cin>>n;
	fori(i,1,n) scanf("%d",&a[i]);
	fori(i,1,n-2)
	if ((a[i]^a[i+1])>a[i+2])
	{cout<<1<<endl;return 0;}
	ans=inf;
	fori(i,1,n-1)
	{
		w1=0;
		ford(j,i,max(i-30,1))
	     {
	     	w1=w1^a[j];
	     	w2=0;
	     	fori(k,i+1,min(n,i+30))
	     	{
	     		w2=w2^a[k];
	     		if (w1>w2) {
	     			ans=min(ans,k-j-1);
	     			break;
	     		}
	     	}
     	 }
	}
	if (ans==inf) cout<<-1<<endl;
	else cout<<ans<<endl;
}

#include<bits/stdc++.h>

typedef long long ll;
typedef long double ld;
using namespace std;
//mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 mrand(42);
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define al(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define asdd cout<<"okok"<<endl;
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl;
#define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl;
#define pc(x) __builtin_popcount(x)
#define pb push_back
#define PS string qqwwee;cin>>qqwwee;
typedef pair<int, int> pii;

int a[105];
int main() {
    int n;
    cin>>n;
    if(n>100) return cout<<1<<endl,0;
    for(int i=1;i<=n;++i) cin>>a[i];
    int ans=1e9;
    for(int i=1;i<n;++i) {
        int x=0;
        for(int j=i;j>=1;--j) {
            x^=a[j];
            int cnt1=i-j;
            int y=0;
            for(int k=i+1;k<=n;++k) {
                y^=a[k];
                int cnt2=k-i-1;
                if(x > y) ans=min(ans,cnt1+cnt2);
            }
        }
    }
    if(ans <= n) cout << ans << endl;
    else cout << -1 << endl;
}

#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
#define gcd __gcd
const int N = 1e5 + 10;

int a[N], sum[N];
int dp[110][110];

void solve() {
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		sum[i] = a[i] ^ sum[i - 1];
	}
	if(n > 100) {
		puts("1");
		return;
	}
	for(int i = 1; i <= n; i++) {
		dp[i][i] = a[i];
		for(int j = i + 1; j <= n; j++) {
			dp[i][j] = sum[j] ^ sum[i - 1];
		}
	}
	int res = 1e9;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= i; j++) {
			for(int k = i + 1; k <= n; k++) {
				if(dp[j][i] > dp[i + 1][k]) {
					// cout << j << " " << i << " " << k << endl;
					res = min(k - j - 1, res);
				}
			}
		}
	}
	if(res == 1e9) res = -1;
	printf("%d\n", res);
}

int main() {
	// freopen("in.txt", "r", stdin);
	// int t; cin >> t; while(t--)
	solve();
	return 0;
}

#include <iostream>
#include <cstdio>
using namespace std;
int n;
int a[1000010];
int maxbit(int o)
{
	while(o)
	{
		if(o == (o & -o))
		return o;
		o -= o & -o;
	}
}
int main()
{
	scanf("%d", &n);
	int tot = 0, be = 0, flag = 0;
	for (int i = 1; i <= n; ++ i)
	{
		scanf("%d", &a[i]);
		if(be != maxbit(a[i]))
		{
			be = maxbit(a[i]);
			tot = 1;
		}
		else
		{
			++ tot;
			if(tot == 3)
			{
				flag = 1;
			}
		}
	}
	if(flag)
	{
		printf("1");
		return 0;
	}
	int ans = 1e9;
	for (int i = 1; i <= n; ++ i)
	{
		int x1 = 0;
		for (int j = i; j >= 1; -- j)
		{
			x1 ^= a[j];
			int x2 = 0;
			for (int k = i + 1; k <= n; ++ k)
			{
				x2 ^= a[k];
				if(x1 > x2)
				{
					ans = min(ans, (i - j + k - (i + 1)));
				}
			}
		}
	}
	printf("%d", ans == 1e9 ? -1 : ans);
}

#include <bits/stdc++.h>
using namespace std;
const int oo = 1 << 30;

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, a[100100], s[100100] = {0};
  cin >> n;
  for (int i = 1; i <= n; i++)
  {
    cin >> a[i];
    s[i] = s[i - 1] ^ a[i];
  }

  int ans = n + 1;
  for (int i = 0; i < n; i++)
    for (int j = i + 2; j <= min(n, i + 33); j++)
      for (int k = i + 1; k < j; k++)
        if ((s[k] ^ s[i]) > (s[k] ^ s[j]))
          ans = min(ans, j - i - 2);

  cout << (ans <= n ? ans : -1) << endl;
}

#include <iostream>
#include <fstream>
#include <numeric>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <deque>
#include <bitset>
#include <cstring>
#include <sstream>
#include <complex>

#define f first
#define s second
#define ll long long
#define ld long double
#define pb push_back
#define all(x) x.begin(),x.end()
#define mp make_pair
#define y0 eto
#define y1 mezhdy
#define y2 nami
#define left extermination
#define right dismemberment

using namespace std;

double start_moment = 0;
double get_runtime() { return 1.0*clock()/CLOCKS_PER_SEC; }
void reset_timer() { start_moment = get_runtime(); }
double timer_time() { return get_runtime() - start_moment; }
void runtime(){ cout<<fixed<<setprecision(5)<<get_runtime()<<'\n'; }

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template <class T>void read(vector<T> &a,ll n){T x; a.clear();for(ll i=0;i<n;i++){cin>>x;a.pb(x);}}
template <class T>void write(vector<T> &a){for(T x : a) cout<<x<<' ';cout<<'\n';}

int n;
vector<int> a;
vector<int> xr;

int mx_bit(int x) {
    for(int i=30;i>=0;i--) {
        if(x&(1<<i)) {
            return i;
        }
    }
    return 0;
}

int get(int l,int r) {
    return xr[r+1]^xr[l];
}

int main()
{
    ios_base::sync_with_stdio(0);
//    freopen("INPUT.txt", "r", stdin);
//    freopen("OUTPUT.txt", "w", stdout);

    cin>>n;
    read(a,n);
    for(int i=2;i<n;i++) {
        if(mx_bit(a[i-2]) == mx_bit(a[i-1]) && mx_bit(a[i-2]) == mx_bit(a[i])) {
            cout<<1;
            return 0;
        }
    }
    xr.pb(0);
    for(int i=0;i<a.size();i++) {
        xr.pb(xr.back()^a[i]);
    }

    int ans=666;

    for(int i=0;i<n;i++) {
        for(int x=1;x<=65;x++) {
            for(int y=1;y<=65;y++) {
                if(i+x+y-1>=n) continue;
                int f1=get(i,i+x-1);
                int f2=get(i+x,i+x+y-1);
                if(f1>f2) {
                    ans=min(ans,x-1+y-1);
                }
            }
        }
    }

    for(int i=0;i<n;i++) {
        for(int x=1;x<=65;x++) {
            for(int y=1;y<=65;y++) {
                for(int z=1;z<=65;z++) {
                    if(i+x+y+z-1>=n) continue;
                    int f1=get(i,i+x-1);
                    int f2=get(i+x,i+x+y-1);
                    int f3=get(i+x+y,i+x+y+z-1);
                    if(f1>f2 || f2>f3) {
                        ans=min(ans,x-1+y-1+z-1);
                    }
                }
            }
        }
    }

    if(ans==666) {
        cout<<-1;
    } else {
        cout<<ans;
    }

}

#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
const int N = 1e5 + 10, Log = 30;
int n, a[N], s[N];

int main()
{
  scanf("%d", &n);
  for(int i = 1; i <= n; i++) scanf("%d", &a[i]), s[i] = s[i - 1] ^ a[i];
  if(n >= 200) return printf("1\n"), 0;
  int ans = n + 5;
  for(int i = 0; i <= n; i++)
  {
    for(int j = i + 1; j <= n; j++)
    {
      for(int k = j + 1; k <= n; k++)
      {
        if((s[i] ^ s[j]) > (s[j] ^ s[k])) ans = min(ans, j - i - 1 + k - j - 1);
      }
    }
  }
  if(ans >= n + 5) printf("-1\n");
  else printf("%d\n", ans);
	return 0;
}

/** I can do this all day **/

#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;

typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"

const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ll inf = 8e18;
const int LOG = 22;

ll pw(ll a , ll b, ll M)  { return (!b ? 1 : (b & 1 ? (a * pw(a * a % M, b / 2, M)) % M : pw(a * a % M, b / 2, M))); }

int A[N], P[N];

int main()
{
    fast_io;
    int n;
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        cin >> A[i], P[i] = A[i] ^ P[i - 1];
    }
    if (n <= 100)
    {
        int Mn = 1e9;
        for (int l = 0; l <= n; l ++)
            for (int md = l + 1; md <= n; md ++)
                for (int r = md + 1; r <= n; r ++)
                    if ((P[r] ^ P[md]) < (P[md] ^ P[l]))
                        Mn = min(Mn, r - l - 2);
        if (Mn > n) Mn = -1;
        cout << Mn << "\n";
        return 0;
    }
    cout << 1 << "\n";
    return 0;
}
/*!
        stay away from negative people they have a problem for every solution !
*/

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define LL long long
#define pii pair<int,int>
#define pll pair<LL,LL>
#define mkp(x,y) make_pair(x,y)
#define fi first
#define se second
#define maxn 100005

using namespace std;

int n,a[maxn],b[maxn],pre[maxn];

int main()
{
    cin >>n;
    for (int i=1;i<=n;i++) cin >>a[i];
    for (int i=1;i<=n;i++) if (a[i]==a[i+1] && (i!=0 && a[i-1]!=0))
    {
        cout <<1;
        return 0;
    }
    for (int i=1;i<=n;i++)
        for (int j=30;j>=0;j--) if ((1<<j)&a[i]) {b[i]=j; break;}
    for (int i=2;i<n;i++) if (b[i]==b[i-1] && b[i]==b[i+1])
    {
        cout<<1;
        return 0;
    }
    int ans=0x7fffffff;
    for (int i=1;i<=n;i++) pre[i]=pre[i-1]^a[i];
    for (int len=1;len<=n;len++)
        for (int l=1;len+l-1<=n;l++)
        {
            int r=l+len-1;
            for (int k=l;k<r;k++) if ((pre[l-1]^pre[k])>(pre[k]^pre[r])) ans=min(ans,r-l-1);
        }
    if (ans==0x7fffffff) cout<<-1;
    else cout<<ans;
    printf("\n");
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mp make_pair
#define mt make_tuple

const int INF = 1e9+9;
const int MAXN = 3e5 + 5;
const int  MOD = 998244353;

signed main() {
    fastio;
    //freopen("INPUT.TXT", "r", stdin);
    //freopen("OUTPUT.TXT", "w", stdout);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)cin >> a[i];
    for(int i = 0; i + 2 < n; ++i){
        if((a[i] ^ a[i + 1]) > a[i + 2]){
            cout << 1;
            return 0;
        }
    }
    for(int i = n - 1; i - 2 >= 0; --i){
        if((a[i] ^ a[i -1]) < a[i - 2]){
            cout << 1;
            return 0;
        }
    }
    int ans = LLONG_MAX;
    for(int l = 0; l + 1 < n; ++l){
        for(int r = l + 1; r < n; ++r){
            int res1 = 0, res2 = 0;
            for(int i = l; i < r; ++i){
                for(int j = l; j <= i; ++j){
                    res1 ^= a[j];
                }
                for(int j = i + 1; j <= r; ++j){
                    res2 ^= a[j];
                }
                if(res1 > res2){
                    ans = min(ans, r - l - 1);
                }
            }
        }
    }
    cout << ((ans == LLONG_MAX) ? -1 : ans);
    return 0;
}

#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#define ll long long
#define int ll
#define ld long double
#define pb push_back
#define S second
#define F first
#define endl '\n'
#define pii pair < int, int >
#define pld pair < ld, ld >

using namespace std;
mt19937_64 gen(time(0));

const int N = 2e5;
const int M = 1e5 + 10;
const ld eps = 1e-6;
const ld EPS = 1e-3;
const ll inf = 1e15;
const double PI = acos(-1.0);

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("sausage.in", "r", stdin);
//    freopen("sausage.out", "w", stdout);
#endif

    int n;
    cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    vector <int> b(n);
    for (int i = 0; i < n; ++i) {
        int x = a[i], k = 0;
        while (x > 0) {
            x /= 2;
            k++;
        }
        b[i] = k;
    }
    for (int i = 1; i < n - 1; ++i) {
        if (b[i - 1] == b[i] && b[i] == b[i + 1]) {
            cout << 1 << endl;
            return 0;
        }
    }
    int ans = inf;
//    return 0;
//    vector <int> xr(n);
//    xr[0] = a[0];
//    for (int i = 0; i < n; ++i) xr[i] = (xr[i - 1] ^ a[i]);
    for (int l = 0; l < n; ++l) {
        for (int r = l + 1; r < n; ++r) {
            for (int m = l; m <= r; ++m) {
                int x1 = 0, x2 = 0;
                for (int i = l; i < m; ++i) x1 = x1 ^ (a[i]);
                for (int i = m; i <= r; ++i) x2 = x2 ^ (a[i]);
                if (x1 > x2) ans = min(ans, r - l - 1);
            }
        }
    }
    if (ans == inf) ans = -1;
    cout << ans;
    return 0;
}

#include <bits/stdc++.h>
#define _ << ' ' <<
#define ll long long

using namespace std;

const int inf = INT_MAX;

int32_t main()
{
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;
    cin >> n;
    vector < int > a(n + 1), b(n + 5, -1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        int x = a[i], k = 1;
        while(x > 0) {
            if(x % 2) b[i] = k;
            x /= 2;
            k++;
        }
    }

    for(int i = 1; i <= n; i++) {
        if(b[i] == b[i - 1] && b[i] == b[i + 1]) {
            cout << 1 << '\n';
            return 0;
        }
    }

    int ans = inf;

    for(int i = 1; i <= n; i++) {
        for(int j = i + 1; j <= n; j++) {
            for(int m = i; m < j; m++) {
                int x1 = 0, x2 = 0;
                for(int k = i; k <= m; k++) x1 ^= a[k];
                for(int k = m + 1; k <= j; k++) x2 ^= a[k];
                if(x1 > x2) {
                    ans = min(ans, j - i - 1);
                }
            }
        }
    }

    if(ans == inf) ans = -1;
    cout << ans << '\n';
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int a[200005],s[200005],n,ans=0x3f3f3f3f;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i],s[i]=s[i-1]^a[i];
	for(int i=1;i<=n;i++)
		for(int j=0;j<=40&&j<i;j++)
			for(int k=0;k<=40&&i+k<n;k++)
				if((s[i]^s[i-j-1])>(s[i+k+1]^s[i])) ans=min(ans,j+k);
	cout<<(ans==0x3f3f3f3f?-1:ans);
	return 0;
}

#include<bits/stdc++.h>
#define L(i, j, k) for(int i = j, i##E = k; i <= i##E; i++)
#define R(i, j, k) for(int i = j, i##E = k; i >= i##E; i--)
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int, int>
#define mkp make_pair
using namespace std;
const int N = 1e5 + 7;
int n, a[N], qz[N], g[N], p, k, x, y;
void Brute() {
	int ans = 1e9;
	L(i, 1, n) L(l, 0, i - 1) L(r, i + 1, n) if((qz[i] ^ qz[l]) > (qz[i] ^ qz[r])) ans = min(ans, r - l - 2);
	if(ans > 1e8) printf("-1\n");
	else printf("%d\n", ans);
}
int main() {
	scanf("%d", &n);
	L(i, 1, n) scanf("%d", &a[i]), g[i] = log2(a[i]), qz[i] = (qz[i - 1] ^ a[i]);
	L(i, 1, n - 2) if(g[i] == g[i + 1] && g[i + 1] == g[i + 2]) {
		printf("1\n");
		return 0;
	}
	Brute();
	return 0;
}

#include <bits/stdc++.h>
#define FOR(i,a,b) for(register int i=(a);i<(b);++i)
#define ROF(i,a,b) for(register int i=(a);i>=(b);--i)
#define pi pair<int,int>
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define ls(x) ch[x][0]
#define rs(x) ch[x][1]
#define xs(x) (ch[fa[x]][1]==x)
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int ui;
typedef unsigned long long ul;
typedef long long ll;
typedef int n_;
const int maxn = 100005;
const int maxm = 1000005;
const int maxlog = 32;
const int inf = 2147483647;
const double eps = 1e-9;
const double E = 2.718281828459;
const double PI = 3.1415926576;
const long long INF = 9223372036854775807ll;
inline ll qpow(ll a,ll b,ll c){register ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c;b>>=1;}return ans;}
const int mod = 1e9+7;int inv6=qpow(6,mod-2,mod);
inline void dec(n_ &x,n_ y){x-=y,x<0&&(x+=mod);}
inline void add(n_ &x,n_ y){x+=y,x>=mod&&(x-=mod);}
//inline n_ sum(n_ x,n_ y){return x+y<mod?x+y:x+y-mod;}
inline n_ sub(n_ x,n_ y){return x-y<0?x-y+mod:x-y;}
inline n_ sqr(n_ x){return 1ll*x*x%mod;}
inline n_ sm1(n_ x){return (1ll*x*(x+1)>>1)%mod;}
inline n_ sm2(n_ x){return 1ll*x*(x+1)%mod*(2*x+1)%mod*inv6%mod;}
inline n_ sm3(n_ x){return 1ll*sqr(x)*sqr(x+1)%mod;}
namespace IO{
//	#define getchar() (tt == ss && (tt = (ss = In) + fread(In, 1, 1 << 20, stdin), ss == tt) ? EOF : *ss++)
//	char In[1 << 20], *ss=In, *tt=In;//In����Ҫ�������������Ĵ�С
	const int END = 2147483647;//������
	//��������
	inline n_ rd(){//�޸�һ�±������ͼ���(int\ll\ul\ui)
		n_ x=0;int fg=1;
		char c=getchar();
		while(c==' ' || c=='\n')c=getchar();
		if(c=='-')fg=-1,c=getchar();
		while(isdigit(c)){
			x=(x<<3)+(x<<1)+(c-48);
			c=getchar();
		}
		return x*fg;
	}
	//�ַ�������
	inline int rds(char *s){
		register int len=0;
		register char c=getchar();
		while(c==' ' || c=='\n')c=getchar();
		while(c!=' ' && c!='\n' && c!='EOF'){
			s[len++]=c;
			c=getchar();
		}
		return len;
	}
	//����һ���ַ���
	inline int getline(char *s){
		register int len=0;
		register char c=getchar();
		while(c==' ' || c=='\n')c=getchar();
		while(c!='\n' && c!='EOF'){
			s[len++]=c;
			c=getchar();
		}
		return len;
	}
	//�������
	inline void wr(register n_ x){//���ӻ��з�
		if(x<0)putchar('-'),x=-x;
		if(x>=10)wr(x/10);
		putchar(x%10+'0');
	}
	inline void wrn(register n_ x){//�ӻ��з�
		wr(x);
		putchar('\n');
	}
	//��������ʽ�����
	inline void wrd(register n_ x,register int d){//���ӻ��з�
		if(!x){putchar('0');return;}
		register n_ xx =x;
		while(xx)d--,xx/=10;
		FOR(i,0,d)putchar('0');
		wr(x);
	}
	inline void wrdn(register n_ x,register int d){//�ӻ��з�
		wrd(x,d);
		putchar('\n');
	}
	//�ַ������
	inline void wrs(const char *s){//��������з�
		for(register int i=0;s[i];++i)putchar(s[i]);
	}
	inline void wrsn(const char *s){//������з�
		wrs(s);
		putchar('\n');
	}
	inline void debug(const char *s,n_ a=END,n_ b=END,n_ c=END,n_ d=END,n_ e=END,n_ f=END){
		if(s!=NULL)wrs(s),putchar(' ');
		if(a!=END)wr(a),putchar(' ');
		if(b!=END)wr(b),putchar(' ');
		if(c!=END)wr(c),putchar(' ');
		if(d!=END)wr(d),putchar(' ');
		if(e!=END)wr(e),putchar(' ');
		if(f!=END)wr(f),putchar(' ');
		putchar('\n');
	}
}
using namespace IO;

int a[maxn],cnt[maxlog],h[maxn],sum[maxn];

int cal(int cur,int x){
	int ans=0,cct=-1,as=inf/2;
	ROF(i,cur,1){
		int xx=0,ct=0;
		ROF(j,i,1){
			xx^=a[j];
			ct++;
			if(xx>x)as=min(as,cct+ct);
		}
		x^=a[i];
		cct++;
	}
	return as;
}
int main(){
	int n;scanf("%d",&n);
	FOR(i,1,n+1){
		scanf("%d",&a[i]);
		ROF(j,maxlog-1,0){
			if((1<<j)&a[i]){
				cnt[j]++;
				h[i]=j;
				break;
			}
		}
	}
	FOR(i,0,maxlog){
		if(cnt[i]>=3)return wrn(1),0;
	}
	int ans=inf/2;
	sum[1]=a[1];
	FOR(i,2,n+1){
		sum[i]=sum[i-1]^a[i];
		if(i<n && h[i]==h[i+1]){
			ans=min(ans,cal(i-1,a[i]^a[i+1])+1);
		}
		ans=min(ans,cal(i-1,a[i]));
	}
	if(ans==inf/2)return wrn(-1),0;
	printf("%d\n",ans);
}

#include<bits/stdc++.h>
#ifdef LOCAL
#include<ctime>
#include<windows.h>
#include<random>
#include"file.h"
#define __int128 LL
#endif

#define y1 zyy_orz
#define hash sto_zyy

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL>pLL;
typedef pair<int, int>pii;
const double eps = 1e-10;
const double PI = 3.1415926535897932;
const int dir[4][2] = { -1,0,0,-1,1,0,0,1 };
//const int dir[8][2] = { -1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1 };
//const int dir[8][2] = { -2,-1,-2,1,2,-1,2,1,-1,2,-1,-2,1,2,1,-2 };

const int maxn = 1e7 + 5;
int trie[maxn][2];
int n;
int w[maxn];
int base = 30;

int pre[maxn];
int suf[maxn];
int s[maxn];
int pn;

void insert(int x){
	int p = 1;
	for (int i = base; i >= 0; i--) {
		int idx = (x >> base & 1);
		if (!trie[p][idx])trie[p][idx] = ++pn;
		p = trie[p][idx];
	}
}

int main() {
#ifdef LOCAL
	fileopen();
#endif
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)scanf("%d", &w[i]), s[i] = s[i - 1] ^ w[i];

	int ans = 1e9;
	for (int i = 1; i <= n; i++) {
		int a = i, b = i + 1;
		for (int j = max(a - 31, 1); j <= a; j++) {
			for (int k = b; k <= min(b + 31, n); k++) {
				int u = s[a] ^ s[j - 1];
				int v = s[k] ^ s[b - 1];
				if (u > v)
					ans = min(ans, k - j - 1);
			}
		}
	}
	if (ans > 1e8)ans = -1;
	printf("%d\n", ans);

#ifdef LOCAL
	fileclose();
#endif
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, a[100100] = {0};
  cin >> n;
  for (int i = 1; i <= n; i++)
  {
    cin >> a[i];
    a[i] ^= a[i - 1];
  }

  if (n > 60)
  {
    cout << 1 << endl;
    return 0;
  }

  int ans = n + 1;
  for (int i = 0; i < n; i++)
    for (int j = i + 2; j <= n; j++)
      for (int k = i + 1; k < j; k++)
        if ((a[k] ^ a[i]) > (a[k] ^ a[j]))
          ans = min(ans, j - i - 2);

  cout << (ans <= n ? ans : -1) << endl;
}

// M
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const int N = 1e6 + 19, Mod = 1e9 + 7;
int n, m, q, A[N], P[N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i ++)
        cin >> A[i], P[i] = A[i] ^ P[i - 1];
    if (n <= 100)
    {
        int Mn = 1e9;
        for (int l = 0; l <= n; l ++)
            for (int md = l + 1; md <= n; md ++)
                for (int r = md + 1; r <= n; r ++)
                    if ((P[r] ^ P[md]) < (P[md] ^ P[l]))
                        Mn = min(Mn, r - l - 2);
        if (Mn > n)
            Mn = -1;
        cout << Mn << "\n";
        return 0;
    }
    cout << 1 << "\n";
    return 0;
}

#include <bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	register int x=0;
	register bool f=0;
	register char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-48;
		c=getchar();
	}
	return f?-x:x;
}
char cr[200],str[200];int tt;
inline void print(int x,char k='\n') {
    if(!x) putchar('0');
    if(x < 0) putchar('-'),x=-x;
    while(x) cr[++tt]=x%10+'0',x/=10;
    while(tt) putchar(cr[tt--]);
    putchar(k);
}
int get(int x){
	int tmp;
	while(x){
		x-=tmp=(x&-x);
	}
	return tmp;
}
const int maxn=1e6+10;
int n,a[maxn],b[maxn];
signed main(){
	n=read();
	for(int i=1;i<=n;i++){
		b[i]=get(a[i]=read());
		if(b[i]=b[i-1]=b[i-2]){
			puts("1");
			return 0;
		}
	}
	for(int len=1;len<n;len++){
		for(int l=1;l<n-len;l++){
			int r=l+len+1;
			int ans1,ans2;
			for(int i=l;i<r;i++){
				ans1=0;ans2=0;
				for(int j=l;j<=i;j++){
					ans1^=a[j];
				}
				for(int j=i+1;j<=r;j++){
					ans2^=a[j];
				}
				if(ans1>ans2){
					print(len);
					return 0;
				}
			}
		}
	}
	puts("-1");
	return 0;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
namespace IO{
	#define iL (1<<20)
	char ibuf[iL],*iS=ibuf+iL,*iT=ibuf+iL;
	#define gc() ((iS==iT)?(iT=(iS=ibuf)+fread(ibuf,1,iL,stdin),(iS==iT)?EOF:*iS++):*iS++)
	template<class T>inline void read(T &x){
		register char c;
		for(c=gc();!isdigit(c);c=gc());
		for(x=0;isdigit(c);x=(x<<1)+(x<<3)+(c^48),c=gc());
		return ;
	}
	char Out[iL],*iter=Out;
	#define flush() fwrite(Out,1,iter-Out,stdout),iter=Out
	template<class T>inline void write(register T x){
		register T c[35],l;
		for(l=0;!l || x;c[l]=x%10,++l,x/=10);
		for(;l;--l,*iter++=c[l]+'0');
		flush();
		return ;
	}
	template<class T>inline void write(register T x,register char LC){
		write(x),*iter++=LC;
		return ;
	}
}
using namespace IO;
int n,ans=1e9;
ll a[100005],sum[100005];
int main(){
//	freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
	read(n);
//	if(n>70){
//		printf("1");
//		return 0;
//	}
	for(register int i=1;i<=n;++i){
		read(a[i]);
	}
	for(register int i=1;i<=n;++i){
		sum[i]=sum[i-1]^a[i];
	}
	for(register int i=1;i<n;++i){
		for(register int j=i+1;j<=n;++j){
			bool f=false;
			for(register int k=i;k<j;++k){
				if((sum[k]^sum[i-1])>(sum[j]^sum[k])){
					f=true;
					break;
				}
			}
			if(f){
				ans=min(ans,j-i-1);
				break;
			}
		}
	}
	if(ans!=1e9){
		write(ans);
	}
	else{
		printf("-1");
	}
	return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef long long ll;
typedef long double ld;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second

template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

//DEBUG TEMPLATE POCINJE OVDE

void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for(auto z : x) cerr << (f++ ? "," : ""), __print(z); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if(sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef ljuba
#define debug(x...) cerr << "LINE(" << __LINE__ << ") -> " << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

//DEBUG TEMPLATE SE ZAVRSAVA OVDE

const char nl = '\n';

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    vector<ll> v(n);
    for(auto &z : v)
        cin >> z;

    for(int i = 0; i + 2 < n; ++i) {
        if((v[i]^v[i+1]) > v[i+2]) {
            cout << 1 << nl;
            return 0;
        }
    }

    for(int i = 0; i + 2 < n; ++i) {
        if(v[i] > (v[i+1]^v[i+2])) {
            cout << 1 << nl;
            return 0;
        }
    }

    int ans = 1e9;
    for(int i = 0; i + 1 < n; ++i) {
        ll x = 0;
        for(int j = i; ~j; --j) {
            x ^= v[j];
            ll x2 = 0;
            for(int k = i+1; k < n; ++k) {
                x2 ^= v[k];
                if(x > x2)
                    ckmin(ans, (i-j) + (k - (i+1)));
            }
        }
    }

    cout << (ans == 1e9 ? -1 : ans) << nl;
}

#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <deque>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector<int> a(n + 2);
	for (int i = 0; i < n; i++) {
		cin >> a[i + 1];
	}
	a[0] = -1;
	a[n + 1] = (1 << 30);
	if (n > 70) {
		cout << 1;
		return 0;
	}
	int ans = 1e9;
	for (int i = 0; i <= n; i++) {
		int nw1 = 0; int nw2 = 0;
		for (int j = i; j >= 0; j--) {
			nw1 ^= a[j];
			nw2 = 0;
			for (int u = i + 1; u <= n + 1; u++) {
				nw2 ^= a[u];
				if (nw1 > nw2) {
					ans = min(ans, u - j - 1);
				}
			}
		}
	}
	if (ans == 1e9) {
		cout << -1;
	}
	else {
		cout << ans;
	}
}
//-1 1 2 5 6 8 100

#include <bits/stdc++.h>
using namespace std;

using lli = long long int;
using pi = pair<int,int>;
const int N = 1000100, mod = 1e9+7;
#define rep(n) for(int i=0; i<n; i++)
#define read(arr, n) rep(n) cin >> arr[i];
#define print(arr, n) rep(n) cout << arr[i] << (i==n-1 ? '\n' : ' ');
#define f first
#define s second
void debug(int num, ...) {va_list valist;va_start(valist, num);for(int i=0; i<num; i++)cout << va_arg(valist, int) << ' ';va_end(valist);cout << endl;}

void solve() {
    int n, arr[N] = {0};
    cin >> n;
    for(int i=1; i<=n; i++) {
        cin >> arr[i];
        arr[i] ^= arr[i-1];
    }
    for(int k=3; k<=n; k++) {
        for(int i=0; i+k<=n; i++) {
            for(int j=i+1; j<i+k; j++) {
                if((arr[j]^arr[i])>(arr[i+k]^arr[j])) {
                    cout << k-2 << '\n';
                    return;
                }
            }
        }
    }
    cout << -1 << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    //int _t; cin >> _t; while(_t--)
    solve();
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

const long long INF = 1000000000000;

int main()
{
    long long n;
    cin >> n;
    vector<long long> data(n);
    for (long long i = 0; i < n; ++i) {
        cin >> data[i];
    }
    if (n > 100) {
        cout << 1;
        return 0;
    }
    long long ans = INF;
    for (long long k = 0; k < n; ++k) {
        long long fir = 0;
        for (long long i = k; i >= 0; i--) {
            fir ^= data[i];
            long long sec = 0;
            for (long long j = k + 1; j < n; ++j) {
                sec ^= data[j];
                if (fir > sec) {
                    ans = min(ans, j - i - 1);
                }
            }
        }
    }
    if (ans == INF) {
        cout << -1;
    }
    else {
        cout << ans;
    }
    return 0;
}

//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 100005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,tree[li*4],lazy[li*4],PS[li];
int cev;
string s;
vector<int> v;

inline void build(int node,int start,int end){
	lazy[node]=0;
	if(start==end){tree[node]=b[start];return;}
	build(node*2,start,mid),build(node*2+1,mid+1,end);
	tree[node]=min(tree[node*2],tree[node*2+1]);
}

inline void push(int node,int start,int end){
	if(lazy[node]==0)return ;
	tree[node]^=lazy[node];
	if(start!=end){
		lazy[node*2]^=lazy[node];
		lazy[node*2+1]^=lazy[node];
	}
	lazy[node]=0;
}

inline void update(int node,int start,int end,int l,int r,int val){
	push(node,start,end);
	if(start>end || start>r || end<l)return ;

	int vall=val;
	if(start==end){
		lazy[node]=val;
		push(node,start,end);
		//~ return ;
		//~ vall=0;
	}
	if(start==end)return;
	update(node*2,start,mid,l,r,val),update(node*2+1,mid+1,end,l,r,val);
	tree[node]=min(tree[node*2],tree[node*2+1]);
}

inline int query(int node,int start,int end,int l,int r){
	if(start>end || start>r || end<l)return inf;
	push(node,start,end);
	if(start>=l && end<=r)return tree[node];
	return min(query(node*2,start,mid,l,r),query(node*2+1,mid+1,end,l,r));
}

inline void build1(int node,int start,int end){
	lazy[node]=0;
	if(start==end){tree[node]=b[start];return;}
	build1(node*2,start,mid),build1(node*2+1,mid+1,end);
	tree[node]=max(tree[node*2],tree[node*2+1]);
}

inline void update1(int node,int start,int end,int l,int r,int val){
	push(node,start,end);
	if(start>end || start>r || end<l)return ;

	int vall=val;
	if(start==end){
		lazy[node]=val;
		push(node,start,end);
		vall=0;
		//~ return ;
	}
	if(start==end)return;
	update1(node*2,start,mid,l,r,val),update1(node*2+1,mid+1,end,l,r,val);
	tree[node]=max(tree[node*2],tree[node*2+1]);
}

inline int query1(int node,int start,int end,int l,int r){
	if(start>end || start>r || end<l)return -inf;
	push(node,start,end);
	if(start>=l && end<=r){
		//~ if(l==1 && r==2)cout<<tree[node]<<" :: "<<endl;
		return tree[node];
	}
	return max(query1(node*2,start,mid,l,r),query1(node*2+1,mid+1,end,l,r));
}

int32_t main(void){
	scanf("%lld",&n);
	if(n>65){printf("1\n");return 0;}
	FOR scanf("%lld",&a[i]);
	cev=inf;
	FOR{
		int xorr=0;
		for(int j=i;j>=1;j--){
			xorr^=a[j];
			int xorr1=0;
			for(int jj=i+1;jj<=n;jj++){
				xorr1^=a[jj];
				//~ cout<<xorr<<" :: "<<xorr1<<endl;
				if(xorr>xorr1)cev=min(cev,(jj-i-1+i-j));
			}
		}
	}
	if(cev==inf)cev=-1;
	printf("%lld\n",cev);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
inline int read(void)
{
    int sum = 0;
    int sign = 1;
    char ch = getchar();
    while (ch > '9' || ch < '0')
    {
        if (ch == '-')
        {
            sign = -1;
        }
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        sum = sum * 10 + ch - '0';
        ch = getchar();
    }
    return sum * sign;
}
#define forn(i, n) for (int i = 1; i <= n; i++)
#define fi first
#define sc second
#define mp make_pair
#define INF 0x3f3f3f3f //INT_MAX
#define DNF
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;

int a[maxn];
int sum[maxn];
int main()
{

    int n = read();
    if (n <= 2)
    {
        printf("-1\n");
        return 0;
    }
    if (n > 64)
    {
        printf("1\n");
        return 0;
    }
    for (int i = 1; i <= n; i++)
    {
        a[i] = read();
        sum[i] = sum[i - 1] ^ a[i];
    }
    int ans = INF;
    a[0] = -2147483648, a[n + 1] = INF; //-2147483648
    for (int i = 1; i <= n - 1; i++)
        for (int j = i; j <= n - 1; j++)
            for (int k = j + 1; k <= n; k++)
            {
                int val1 = sum[j] ^ sum[i - 1], val2 = sum[k] ^ sum[j];
                if (val1 > val2)
                    ans = min(ans, k - i - 1);
            }
    if (ans == INF)
        printf("-1\n");
    else
        printf("%d\n", ans);

    return 0;
}

#include<bits/stdc++.h>
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 5;
int c[maxn];

struct node{
    int pos, v;
};

int main(){
    IOS;
    int n, ans, na, nb, ca, cb, cnt, now;
    cin >> n;
    ans = n;
    for(int i = 1; i <= n; i++) cin >> c[i];
    for(int i = 1; i <= n - 1; i++){
        vector<node> a, b;
        a.push_back(node{i, na = c[i]});
        b.push_back(node{i + 1, nb = c[i + 1]});
        for(int j = i - 1; j > i - 32 && j; j--)
            a.push_back(node{j, na ^= c[j]});
        for(int j = i + 2; j <= i + 32 && j <= n; j++)
            b.push_back(node{j, nb ^= c[j]});
        for(auto sb : b){
            for(auto sa : a){
                if(sb.v < sa.v){
                    ans = min(ans, sb.pos - sa.pos - 1);
                }
            }
        }
    }
    cout << (ans == n ? -1 : ans) << endl;
}

#include<bits/stdc++.h>
using namespace std;

//--------------------------Containers------------------------/
typedef     long long int           ll;
typedef     unsigned long long int  ull;
typedef     vector < int >          vi;
typedef     vector < ll >           vll;
typedef     vector < vll >           vvll;
typedef     pair< int,int >         pi;
typedef     pair< ll, ll >          pll;
typedef     vector< pi >            vpi;
typedef     vector< pll >           vpll;
//------------------------------------------------------------/

//--------------------------Limits & Constants----------------/
#define     MAX                 200007
#define     MOD                 int(1e9+7)
#define     INF                 ll(8230219982008199610)
#define     MINF                ll(-8230219982008199610)
#define     IL                  INT_MAX
#define     MIL                 INT_MIN
#define     PI                  2*acos(0.0)
//------------------------------------------------------------/

//--------------------------Macros----------------------------/
#define     fast                ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define     pf                  printf
#define     sc                  scanf
#define     all(a)              (a).begin(),(a).end()
#define     sz(x)               int(x.size())
#define     pb                  push_back
#define     eb                  emplace_back
#define     mp                  make_pair
#define     ff                  first
#define     ss                  second
#define     mem(a,n)            memset(a, n, sizeof(a) )
#define     gcd(a,b)            __gcd(a,b)
#define     lcm(a,b)            (a*(b/gcd(a,b)))
#define     forn(i,n)          for(int i=0; i<n; i++)
#define     loop1(i,n)          for(int i=1; i<=n; i++)
#define     rev0(i,n)           for(int i=n-1; i>=0; i--)
#define     rev1(i,n)           for(int i=n; i>0; i--)
//------------------------------------------------------------/

//----------------------Scans and Prints----------------------/
#define     sc1(x)              scanf("%d",&x)
#define     sc2(x,y)            scanf("%d %d",&x,&y)
#define     sc3(x,y,z)          scanf("%d %d %d",&x,&y,&z)
#define     scd1(x)             scanf("%lld",&x)
#define     scd2(x,y)           scanf("%lld %lld",&x,&y)
#define     pf1(x)              printf("%d\n",x)
#define     pf2(x,y)            printf("%d %d\n",x,y)
#define     pfd1(x)             printf("%lld\n",x)
#define     pfd2(x,y)           printf("%lld %lld\n",x,y)
#define     t_case(t)           for(int cs = 1; cs<=t; cs++)
#define     print(a,n)          for(int pr = 0; pr<int(n); pr++)cout<<a[pr]<<" ";cout<<endl
#define     printa(x)           cout<<x<<endl;
#define     debug               cout<<" OK "<<endl
//------------------------------------------------------------/
ll mul(ll a,ll b){
  return ((a*b))%MOD;
}
ll add(ll a,ll b){
  a+=b;
  if(a>=MOD)a-=MOD;
  return a;
}
ll pow(ll a, ll b, ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
ll nC2(ll n) {
    return add(n*(n+1)/2, 0);
}
bool prim(int n)
{
    for (int i=2; i<=sqrt(n); i++)
    {
        if (n%i == 0)
        {
            return false;

        }
    }
    return true;
}
int main()
{
    ll t;
    //cin>>t;
    t=1;
    ll n,k,x,y;
    while(t--){
        cin>>n;
        vll v(n,0);
        ll f=0;
        vector<pll>p(n);
        for(ll i=0;i<n;i++){
            cin>>v[i];
        }
        if(n > 32 * 2) {cout << 1 << '\n'; continue;}
        ll ans=INF,l,m,r;
        ll curr,curr1;
        for(l=0;l<=n-1;l++){
            curr=v[l];
            for(m=l;m<=n-2;m++){
                curr1=v[m+1];
                if(curr>curr1){
                    ans=min(ans,m-l);
                }
                for(r=m+1;r<n;r++){
                    //cout<<"curr "<<curr<<"\n";
                    //cout<<"curr1 "<<curr1<<"\n";
                    if(r+1<n)curr1^=v[r+1];
                    if(curr>curr1){
                        ans=min(ans,r-l);
                    }
                }
                curr^=v[m+1];
            }
        }
        if(ans==INF){
            cout<<"-1";
            continue;
        }
        cout<<ans;
    }
return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int oo = 1 << 30;

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, a[100100], s[100100] = {0};
  cin >> n;
  for (int i = 1; i <= n; i++)
  {
    cin >> a[i];
    s[i] = s[i - 1] ^ a[i];
  }

  int ans = n + 1;
  for (int i = 0; i < n; i++)
    for (int j = i + 2; j <= min(n, i + 33); j++)
      for (int k = i + 1; k < j; k++)
        if ((s[k] ^ s[i]) > (s[k] ^ s[j]))
          ans = min(ans, j - i - 2);

  cout << (ans <= n ? ans : -1) << endl;
}

/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=1e5+10;
inline int Read(int &r){
	int b=1,c=getchar();r=0;
	while(c<'0' || '9'<c) b=c=='-'? -1:b,c=getchar();
	while('0'<=c && c<='9') r=(r<<1)+(r<<3)+(c^'0'),c=getchar();
	return r*=b;
}

int n;
int num[N];

int main(){
	Read(n);
	for(int i=1;i<=n;i++) Read(num[i]);
	int ans=n+1;
	for(int i=1;i<n;i++){
		for(int l=1,lxor=0;l<=i && l<=60;l++){
			lxor^=num[i-l+1];
			for(int r=1,rxor=0;r<=n-i && r<=60;r++){
				rxor^=num[i+r];
				if(lxor>rxor) ans=min(ans,l+r-2);// ,printf("[%d,%d] - [%d,%d]\n",i-l+1,i,i+1,i+r);
			}
		}
	}
	printf("%d\n",ans==n+1? -1:ans);
	return 0;
}

#include<bits/stdc++.h>

typedef long long ll;
typedef long double ld;
using namespace std;
//mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 mrand(42);
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define al(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define asdd cout<<"okok"<<endl;
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl;
#define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl;
#define pc(x) __builtin_popcount(x)
#define pb push_back
#define PS string qqwwee;cin>>qqwwee;
typedef pair<int, int> pii;

int a[105];
int main() {
    int n;
    cin>>n;
    if(n>100) return cout<<1<<endl,0;
    for(int i=1;i<=n;++i) cin>>a[i];
    int ans=1e9;
    for(int i=1;i<n;++i) {
        int x=0;
        for(int j=i;j>=1;--j) {
            x^=a[j];
            int cnt1=i-j;
            int y=0;
            for(int k=i+1;k<=n;++k) {
                y^=a[k];
                int cnt2=k-i-1;
                if(x > y) ans=min(ans,cnt1+cnt2);
            }
        }
    }
    if(ans <= n) cout << ans << endl;
    else cout << -1 << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define sz(x) ((int)x.size())
#define endl "\n"
#define inf (1LL<<62)
#define ninf (-inf)

int a[100005];
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    if(n >= 100)
    {
        cout << "1\n";
        exit(0);
    }
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    int mn = inf;
    for(int k = 1; k <= n; k++)
    {
        int xori = 0;
        for(int i = k; i >= 1; i--)
        {
            xori ^= a[i];
            int xorj = 0;
            for(int j = k+1; j <= n; j++)
            {
                xorj ^= a[j];
                if(xori > xorj)
                    mn = min(mn, (k-i) + (j-(k+1)));
            }
        }
    }
    if(mn == inf)
        cout << "-1\n";
    else
        cout << mn << "\n";
}

#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include <custom/prettyprint.hpp>
#endif
using namespace std;

typedef long long ll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define sz(x) (int)x.size()
#define dbg(x) cerr << #x << " = " << x << '\n'

const int MOD = 1e9+7; //998244353;
const int inf = 1e9+3;
const ll INF = ll(3e18)+3;

void setIO(const string& s) {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen((s+".in").c_str(),"r",stdin);
//	freopen((s+".out").c_str(),"w",stdout);
#endif
}

signed main() {
    setIO("input");

    int n; cin >> n;
    vector<int> arr(n+1);
    for(int i=1; i<=n; ++i) {
        cin >> arr[i];
    }

    if(n >= 62) {
        cout << "1\n";
        return 0;
    }

    int ans = inf;
    for(int i=1; i<=n-1; ++i) {
        int l = 0;
        for(int j=i; j>=1; --j) {
            l ^= arr[j];
            int r = 0;
            for(int k=i+1; k<=n; ++k) {
                r ^= arr[k];
                if(r < l) {
                    ans = min(ans, k-j-1);
                }
            }
        }
    }
    cout << (ans==inf ? -1 : ans) << '\n';

}

#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef long double ld;

ll a[100010];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n;
	cin>>n;
	for (ll i=0; i<n; ++i) cin>>a[i];
	if (n>100) {cout<<1<<endl; return 0;}
	ll best = LLONG_MAX;
	for (ll i=0; i<n; ++i) {
		for (ll j=i+1; j<n; ++j) {
			for (ll m=i; m<j; ++m) {
				ll l=0, r=0;
				for (ll u=i; u<=m; ++u) l^=a[u];
				for (ll u=m+1; u<=j; ++u) r^=a[u];
				if (r<l) {
					best=min(best, j-i+1-2);
				}
			}
		}
	}
	if (best==LLONG_MAX)cout<<-1<<endl;
	else cout<<best<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e6+10;
const int mod=1e9+7;
ll t,n,cnt,k,p,x,y;
ll a[maxn];
ll flag;
ll b[maxn];
int main()
{
    cin>>n;
    if(n>=100)
    {
        cout<<1<<endl;
        return 0;
    }
    b[0]=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        ll u=a[i];
        b[i]=b[i-1]^a[i];
    }
    ll min1=mod;
    for(int i=1;i<=n;i++) {
        for (int j = i; j <= n; j++) {
            for (int ii = j + 1; ii <= n; ii++) {
                for (int jj = ii; jj <= n; jj++) {
                    if((b[j]^b[i-1]) > (b[jj]^b[ii-1])) {
                        //cout<< i <<" "<< j<< " " << ii <<" "<<jj<<endl;
                        //cout<< (b[j]^b[i-1])<< " " <<(b[jj]^b[ii-1])<<endl;
                        //cout<<min1<<endl;
                        min1 = min(min1, 1LL + j - i + jj - ii);
                    }
                }
            }
        }
    }
    if(min1==mod)
    {
        cout<<-1<<endl;
    }
    else
        cout<<min1-1<<endl;
    return 0;
}

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>

using namespace std;

typedef long long ll;
typedef string ss;

#define pb push_back
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

const int N = 3e5 + 5, INF = int(1e9), mod = int(1e9) + 9, base = 1;

int n, a[N], ans = INF;

int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    if(n >= 100){
        cout << 1 << endl;
        return 0;
    }
    for(int i = 1; i <= n; i++){
        for(int l = 1; l <= i; l++){
            for(int r = i + 1; r <= n; r++){
                int res1 = 0;
                for(int j = l; j <= i; j++){
                    res1 ^= a[j];
                }
                int res2 = 0;
                for(int j = i + 1; j <= r; j++){
                    res2 ^= a[j];
                }
                if(res1 > res2){
                    ans = min(ans, i - l + r - (i + 1));
                }
            }
        }
    }
    if(ans != INF)
        cout << ans << endl;
    else
        cout << -1 << endl;
}

// https://codeforces.com/contest/1457/problem/D

#include <bits/stdc++.h>
using namespace std;
#define cerr if(false) cerr
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define endl '\n'
#define ld long double
// #define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define sz(a) (int)a.size()
#define all(x) (x).begin(), (x).end()

void solve() {

}

const int maxn = 100500;

int n;
int a[maxn];
int pre[maxn];

int query(int l, int r) {
    if(l > r) return 0;

    return pre[r]^pre[l-1];
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        pre[i] = pre[i-1]^a[i];
    }

    a[0] = INT_MIN;
    a[n+1] = INT_MAX;

    int ans = INT_MAX;
    for(int i = 1; i <= n; i++) {
        for(int j = i; j <= min(i+30, n); j++) {
            for(int k = i; k < j; k++) {
                int l = query(i, k);
                int r = query(k+1, j);

                int moves = k-i + j-(k+1);

                if(l > r) {
                    ans = min(ans, moves);
                }

                if(i > 1 and a[i-1]>l) {
                    ans = min(ans, moves);
                }

                if(j < n and r>a[j+1]) {
                    ans = min(ans, moves);
                }
            }
        }
    }

    if(ans == INT_MAX) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }

    // if(ans > 2) assert(false);
}

/*

n^3
90 000 000

96 100 000
*/

// Did you read the bounds?
// Did you make typos?
// Are there edge cases (N=1?)
// Are array sizes proper?
// Integer overflow?
// DS reset properly between test cases?
// Is using long longs causing TLE?
// Are you using floating points?

#include "stdio.h"
#include "algorithm"
#include "stdlib.h"
#include "set"
#include "map"
#include "queue"
#include "vector"
#include "math.h"
#include "stack"

// #define int long long

int Max(int a, int b) {
	return a > b? a: b;
}
int Min(int a, int b) {
	return a < b? a: b;
}
int Abs(int a) {
	return a < 0? -a: a;
}
int sqr(int a) {
	return (long long)a * a;
}

// #undef int

int T;
int n;
int a[100010];
int b[100010];

main() {
	// scanf("%lld", &T);
	T = 1;
	while (T --) {
		scanf("%d", &n);
		for (int i = 1; i <= n; ++ i)
			scanf("%d", a + i);
		int p = 0;
		for (int i = 1; i <= n; ++ i) {
			if ((1 << p + 1) <= a[i])
				++ p;
			if (++ b[p] > 2) {
				printf("1");
				return 0;
			}
		}
		for (int i = 1; i <= n; ++ i)
			b[i] = b[i - 1] ^ a[i];
		int ans = 200000;
		for (int i = 2; i <= n; ++ i)
			for (int j = i - 1; j; -- j)
				for (int k = j - 1; ~k; -- k) {
					if ((b[i] ^ b[j]) < (b[j] ^ b[k]))
						ans = Min(ans, i - k - 2);
					// printf("%d %d %d %d\n", i, j, k, ans);
				}
		if (ans < 200000)
			printf("%d\n", ans);
		else
			puts("-1");
	}
	#ifndef ONLINE_JUDGE
		while (1);
	#endif
}

/*
6424446
6464244

*/

#include <bits/stdc++.h>
using namespace std;

#define co(n) cout<<n<<endl;
const double eps=1e-10,pi=3.1415926535898;
const int mod=1e9+7,maxn=2e5+10;
int T,n,m,x,y,a[maxn],b[maxn];

int main(int argc, char const *argv[]) {
	//init();
	T = 1;
	//scanf("%d", &T);
	for (int _=1;_<=T;++_) {
		int ans=maxn;
		scanf("%d", &n);
		for (int i=1;i<=n;++i) {
			scanf("%d", a+i);
			b[i] = 0;
			for (int j=0;j<30;++j) {
				if (a[i]&(1<<j)) {
					b[i] = j;
				}
			}
		}
		int flag=0;
		for (int i=3;i<=n;++i) {
			if (b[i]==b[i-1] and b[i]==b[i-2]) {
				flag = 1;
				break;
			}
		}
		if (flag) {
			printf("1\n");
			continue;
		}
		for (int i=1;i<=n;++i) {
			x = 0;
			for (int j=i;j<=n;++j) {
				x ^= a[j];
				for (int k=j+1;k<=n;++k) {
					y = 0;
					for (int l=k;l<=n;++l) {
						y ^= a[l];
						if (x > y) {
							ans = min(ans, j-i+l-k);
						}
					}
				}
			}
		}
		if (ans!=maxn) printf("%d\n", ans);
		else printf("-1\n");
	}
	return 0;
}

/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
clock_t clk;
clk = clock();
if(clock() - clk > CLOCKS_PER_SEC * 0.9)
      T
W     L
A C M E R
  E L   E
    E
*/

#include<bits/stdc++.h>
using namespace std;
int a[200005],s[200005],n,ans=0x3f3f3f3f;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i],s[i]=s[i-1]^a[i];
	for(int i=1;i<=n;i++)
		for(int j=0;j<=40&&j<i;j++)
			for(int k=0;k<=40&&i+k<n;k++)
				if((s[i]^s[i-j-1])>(s[i+k+1]^s[i])) ans=min(ans,j+k);
	cout<<(ans==0x3f3f3f3f?-1:ans);
	return 0;
}

/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define pb     push_back
#define inf     2e18
#define low     -2e18
#define PI        acos(-1.0)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
const int sz = 3e5+9;
ll a[sz],b[sz];
string str,str2;
int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    FAST
    cin>>n;

    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    if(n>70)
    {
        cout<<"1"<<endl;
        return 0;
    }
    ll ans = inf;
    ll p;
    for(i=0;i<n;i++)
    {
        x = 0;
        for(j=i;j<n;j++)
        {
            x = x ^ a[j];
            y = 0;
            for(k=j+1;k<n;k++)
            {
                y = y ^ a[k];
                if(y<x)
                {

                    ans = min(ans,j-i+k-(j+1));
                }
            }
        }
    }
    if(ans==inf)
        cout<<-1<<endl;
    else
    cout<<ans<<endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}
template <typename T> ostream& operator<<(ostream &os, const vector<T> &v){print(v); return os;};
template <typename T> ostream& operator<<(ostream &os, const vector<vector<T>> &vv){print_vv(vv); return os;};
template <class T, class U> ostream& operator<<(ostream &os, const map<T,U>  &m){print_m(m); return os;};
template <class T, class U> ostream& operator<<(ostream &os, const pair<T, U> &pr){debp(pr); return os;};
template <class T, class U> ostream& operator<<(ostream &os, const vector<pair<T, U>> &vp){ print_vp(vp); return os;};

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    while(cin>>n){
        vi a(n); forn(i,n) cin>>a[i];
        int ans = n;
        forn(i,n-1){
            int lxr = 0;
            for(int lt=i; lt>=max(i-60,0); --lt){
                lxr^=a[lt];
                int rxr = 0;
                for(int rt=i+1; rt<min(i+60,n); ++rt){
                    rxr^=a[rt];
                    if(lxr>rxr){
                        min_self(ans, rt-lt-1);
                    }
                }
            }
        }
        if(ans>=n-1) ans = -1;
        cout<<ans<<"\n";
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define max(a,b) (a>b ? a:b)
#define min(a,b) (a<b ? a:b)
#define swap(a,b) (a^=b^=a^=b)
#define maxn 105000
#define minn -105
#define ll long long int
#define ull unsigned long long int
#define uint unsigned int
inline int read()
{
    int ans=0;
    char last=' ',ch=getchar();
    while(ch<'0'|ch>'9')last=ch,ch=getchar();
    while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar();
    if(last=='-')ans=-ans;
    return ans;
}
int n;
int a[maxn];
int cnt[105];
int pre[maxn];
int h(int x)
{
    int ttt=-1;
    while(x)
    {
        ttt++;
        x>>=1;
    }
    return ttt;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        pre[i]=a[i];
        pre[i]^=pre[i-1];
        //cout<<pre[i]<<endl;
        cnt[h(a[i])]++;
    }
    bool mt=0;
    for(int i=0;i<=n;i++)
    {
        if(cnt[i]>=3)
        {
            cout<<"1\n";
            return 0;
        }

    }
    int ans=INF;
    for(int i=1;i<=n;i++)
        for(int j=i;j<=n;j++)
            for(int k=j+1;k<=n;k++)
            {
                if((pre[i-1]^pre[j])>(pre[j]^pre[k]))
                {
                    //cout<<i<<j<<k<<endl;
                    ans=min(ans,k-i-1);
                }

            }

    if(ans==INF)cout<<"-1\n";
    else cout<<ans<<"\n";
    return 0;
}

#include<bits/stdc++.h>
#define PI 3.141592653589793238462
#define eps 1e-10
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdd;
ll a[100005],d[100005][35];
int main(){
    ll n,ans=1e9;cin>>n;
    for(ll i=1;i<=n;i++){
        cin>>a[i];
    }
    for(ll i=1;i<=n;i++){
        d[i][0]=a[i];
        for(ll j=i-1;j>=1&&j>=i-31;j--){
            d[i][i-j]=d[i][i-j-1]^a[j];
        }
    }
    for(ll i=2;i<=n;i++){
        for(ll j=0;j<i-1&&j<=31;j++){
            for(ll k=0;k<i-j-1&&k<=31;k++){
                if(d[i][j]<d[i-j-1][k]){
                    ans=min(ans,j+k);
                }
            }
        }
    }
    if(ans>1e7) cout<<-1<<endl;
    else cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll n, a[102], pre[102];

inline ll get(ll l, ll r) { return pre[r] ^ pre[l - 1]; }

int main()
{
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	if (n >= 60) cout << 1;
	else
	{
		for (ll i = 1; i <= n; i++) {
			cin >> a[i];
			pre[i] = pre[i - 1] ^ a[i];
		}
		ll ans = 1e9 + 1;
		ll mx = ans;
		for (ll i = 1; i <= n; i++)
			for (ll j = i + 1; j <= n; j++)
				for (ll k = i; k < j; k++)
					if (get(i, k) > get(k + 1, j))
						ans = min(ans, j - i - 1);
		cout << (ans == mx ? -1 : ans);
	}
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
#include<string>
#include<array>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<numeric>
#include<deque>
#include<functional>
#include<cstring>

#define int long long
#define double long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define forn(n) for(int i = 0; i < n; ++i)
#define rforn(n) for(int i = n - 1; i >= 0; --i)
#define pii pair<int, int>
#define umn(a, b) a = min(a, b)
#define umx(a, b) a = max(a, b)
#define rp(p) cin >> p.first >> p.second

using namespace std;

const int INF = 1e17 + 17;
const int N = 1e5 + 17;
const int mod = 998244353;

void precalc() {

}

void solve() {
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	for (auto& a : a) cin >> a;
	forn (n) {
		int t = a[i], it = 0;
		while (t) t >>= 1, ++it;
		b[i] = it;
	}
	for (int i = 2; i < n; ++i) {
		if (b[i] == b[i - 1] && b[i] == b[i - 2]) {
			cout << 1;
			return;
		}
	}
	int ans = INF;
	for (int i = 0; i < n; ++i) {
		int xrl = 0;
		for (int j = i; j >= 0; --j) {
			xrl ^= a[j];
			int xrr = 0;
			for (int k = i + 1; k < n; ++k) {
				xrr ^= a[k];
				if (xrl > xrr) umn(ans, k - j - 1);
			}
		}
	}
	if (ans == INF) cout << -1;
	else cout << ans;
}

signed main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);

	cout << setprecision(10) << fixed;

	precalc();

	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
		//cout << "\n";
	}

	return 0;
}

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N = 1e5+10;

int n,c[N],z[233],sum[N];

int main()
{
	scanf("%d",&n);
	for(int i=1;i <= n;i++) scanf("%d",&c[i]);
	z[0] = 1;
	for(int i=1;i <= 30;i++) z[i] = z[i-1] << 1;
	if(n > 100) {puts("1");return 0;}
	int ans=1000;
	for(int i=1;i <= n;i++) sum[i] = sum[i-1]^c[i];
	for(int l=1;l < n;l++)
		for(int m=l;m < n;m++){
			for(int r=m+1;r <= n;r++)
			if((sum[r]^sum[m]) < (sum[m]^sum[l-1])) ans = min(ans,r-l-1);
		}
	printf("%d\n",ans >= 1000 ? -1 : ans);
	return 0;
}

/* winners never quit and quitters never win.
      #swap                                 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize ("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

template <typename T>
void make_unique(vector<T>& vec) {
  sort(all(vec));
  vec.erase(unique(all(vec)), vec.end());
}

#define endl '\n'
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pql priority_queue<ll>
#define pqh priority_queue<ll,vc<ll>,greater<ll>>
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll nxt() {
    ll TemporaryVariable;
    cin >> TemporaryVariable;
    return TemporaryVariable;
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	//isprime();
	//coeff();
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    ll n=nxt();
    vc<ll> v(n);
    generate(all(v),nxt);
    ll x[64]={0};
    for(auto y:v)
    {
        ll temp=y,cnt=0;
        while((1LL<<cnt)<=temp)
            cnt++;
        x[cnt-1]++;
    }
    ll maxi=*max_element(x,x+64);
    if(maxi>2)
    {
        cout<<1<<endl;
        exit(0);
    }
    ll ans=inf;
    rep(a,0,n)
    {
        ll curr=0;
        rep(b,a,n)
        {
            curr=(curr^v[b]);
            rep(c,b+1,n)
            {
                ll po=0;
                rep(d,c,n)
                {
                    po=(po^v[d]);
                    ll p=0,p1=0;
                    if(curr>po)
                        ans=min(ans,b-a+d-c);
                }
            }
        }
    }
    if(ans==inf)
        ans=-1;
    cout<<ans<<endl;
	printclock;
	return 0;
}

#include <iostream>
#include <cmath>
#include <math.h>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#include <ctime>
#include <queue>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <random>
#include <cstdio>
#include <string>
#include <numeric>
#include <cctype>
#include <cassert>

#define int long long
#define eb emplace_back
#define rs resize
#define ld long double
#define vi vector<int>
#define vpii vector<pair<int, int>>
#define ull unsigned long long

using namespace std;

// typedef long long ll;
// typedef vector<int> vi;
// typedef long double ld;

/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("vpt")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("shrink-wrap-separate")
#pragma GCC optimize("loop-nest-optimize")
*/

void solve() {
    int n;
    cin >> n;
    vi a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    if (n > 70) {
        cout << "1\n";
        return;
    }
    vi pref_xor(n + 1);
    for (int i = 1; i <= n; i++) {
        pref_xor[i] = a[i] ^ pref_xor[i - 1];
    }

    int ans = 1e9;
    for (int l = 1; l <= n; l++) {
        for (int m = l; m <= n; m++) {
            for (int r = m + 1; r <= n; r++) {
                int val1 = pref_xor[m] ^ pref_xor[l - 1];
                int val2 = pref_xor[r] ^ pref_xor[m];
                if (val1 > val2) {
                    ans = min(ans, m - l + (r - m - 1));
                }
            }
        }
    }
    if (ans == 1e9)ans = -1;
    cout << ans;

}

signed main() {
    // freopen("inverse.in", "r", stdin);
    // freopen("inverse.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed;
    cout.precision(30);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    //   system("pause");
}

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define int long long int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define revrep(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))

ostream &operator<<( ostream &output, const pii &p ) { output << p.first << " " << p.second;return output; }
istream &operator>>( istream &input, pii &p ) { input >> p.first >> p.second;return input; }
template<typename T>
void inline println(vector<T> args){ for(T i: args)cout<<i<<" ";cout<<endl; }
void amax(int& a, int b) { a = max(a, b); }
void amin(int& a, int b) { a = min(a, b); }

int INF = 1e18;
int MOD = 998244353;

void solve()
{
    int n; cin>>n;
    vi arr(n), temp;
    rep(i, 0, n) {
        cin>>arr[i];
        int mx = 0;
        rep(j, 0, 32) if(arr[i]&(1LL<<j)) mx = j;
        temp.pb(mx);
    }
    if(n == 2) {
        cout<<-1<<endl;
        return;
    }
    rep(i, 1, n-1) {
        if(temp[i-1] == temp[i] && temp[i] == temp[i+1]) {
            cout<<1<<endl;
            return;
        }
    }
    int pre[n];
    pre[0] = arr[0];
    rep(i, 1, n) pre[i] = pre[i-1]^arr[i];
    int ans = INF;
    rep(l, 0, n) {
        rep(r, l+1, n) {
            rep(mid, l, r+1) {
                if(mid-l+1 < 1 || r-mid < 1) continue;
                int ll = pre[mid];
                if(l-1 >= 0) ll ^= pre[l-1];
                int rr = pre[r]^pre[mid];
                int lc = mid-l;
                int rc = r-mid-1;
                if(rr < ll) ans = min(ans, lc+rc);
            }
        }
    }
    if(ans == INF) ans = -1;
    cout<<ans<<endl;

}

signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    // cin >> t;
    rep(i, 0, t)
    {
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int n;
int ar[100005];
int pref[100005];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> ar[i];
	}
	int ans = INT_MAX;
	if (n > 64) ans = 1;
	if (ans == 1) {
		cout << ans << endl;
		return 0;
	}
	for (int i = 1; i <= n; i++) {
		pref[i] = pref[i - 1] ^ ar[i];
	}
	for (int i = 1; i < n; i++) {
		for (int k = i; k >= 1; k--) {
			int l = pref[i] ^ pref[k - 1];
			for (int j = i + 1; j <= n; j++) {
				int r = pref[j] ^ pref[i];
				if (l > r) {
					ans = min(ans, i - k + j - i - 1);
				}
			}
		}
	}
	if (ans == INT_MAX) ans = -1;
	cout << ans << endl;
	return 0;
}

// Problem : D. XOR-gun
// Contest : Codeforces - Technocup 2021 - Elimination Round 2
// URL : https://codeforces.com/contest/1415/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

int N;
int arr[100005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> N;
	for(int i = 1; i<=N; i++){
		cin >> arr[i];
		arr[i] ^= arr[i-1];
	}
	if(N > 100){
		cout << 1;
		return 0;
	}
	int ans = 2*N;
	for(int i = 1; i<=N; i++){
		for(int j = i; j<=N; j++){
			for(int k = j+1; k<=N; k++){
				if((arr[i-1]^arr[j]) > (arr[k]^arr[j])){
					ans = min(k - i - 1, ans);
				}
			}
		}
	}
	if(ans == 2*N){
		ans = -1;
	}
	cout << ans;
}

//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
//#define endl '\n'
llo it[100001];
llo pc[2];
llo pre[30][100001];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	llo n;
	cin>>n;
	for(llo i=0;i<n;i++){
		cin>>it[i];
	}
/*	for(int i=1;i<n;i++){
		if((it[i]^it[i+1])<it[i-1]){
			cout<<1<<endl;
			return 0;
		}
	}*/
	llo ans=n+1;
	llo kcc=n+1;
	for(llo i=29;i>=0;i--){
		llo co=0;
	//	llo kk=0;
	//	llo mm=-1;
	//	vector<int> pp;
	//	pp.pb(0);
		llo cot=0;
		for(llo j=0;j<n;j++){
			if(it[j]&(1LL<<i)){
				co+=1;
			}
			pre[i][j+1]=co;
		}

	}
	for(llo i=29;i>=0;i--){
		llo co=pre[i][n];
		if(co==0){
			continue;
		}
		if(co==1){
			n-=1;
			continue;
		}
		if(co>=3){
			ans=min(ans,(llo)1);
			break;
		}
		llo cur=0;
		llo cot=0;
		for(llo j=n-2;j>=0;j--){
			cur^=it[j];
			cot+=1;
			if(cur>it[n-1]){

				ans=min(ans,cot-1);
			}
		}
		llo cur2=0;
		llo coc=0;
		for(int j=n-1;j>=0;j--){
			cur2^=it[j];
			coc+=1;
			if(j<n-1){
				for(int k=29;k>=0;k--){
					if(cur2&(1<<k)){
						if(pre[k][n-1]-pre[k][j]>0){
							ans=min(ans,coc-2);
						}
						else{
							break;
						}
					}
				}
			}
		}
		n-=2;
	}
	if(ans==kcc){
		cout<<-1<<endl;
		return 0;
	}
	cout<<ans<<endl;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rep2(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define sc(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pb push_back
const ll mod=1e9+7;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
ll ad(ll a,ll b)
{
	return ((a%mod)+(b%mod))%mod;
}
ll ap(ll a,ll b)
{
	return ((a%mod)*(b%mod))%mod;
}
ll ksm(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b%2==1)
		res=ap(res,a);
		a=ap(a,a);
		b/=2;
	}
	return res;
}

int hg[100005];
int a[100005];
int sum[100005];
int main(int argc, char** argv) {
	int T;
	T=1;
	while(T--)
	{
		int n;
		sc(n);
		rep(i,1,n)
		{
			sc(a[i]);
		}
		sum[1]=a[1];
		rep(i,2,n)
		{
			sum[i]=sum[i-1]^a[i];
		}
		int ans=1e9;
		rep(i,1,n)
		{
			rep(j,1,42)
			{
				rep(k,1,42)
				{

					if(i+j-1>=n)break;

					if(i-k>=1&&(sum[i-1]^sum[i+j-1])<(sum[i-1]^sum[i-k]))
					{
					//	if(j==2)
					//	cout<<i<<" "<<i+j-1<<" "<<endl;
						ans=min(ans,j-1+k-1);
					}
					if(i+j+k-1<=n&&(sum[i-1]^sum[i+j-1])>(sum[i+j-1]^sum[i+j+k-1]))
					{
						ans=min(ans,j-1+k-1);
					}
				}
			}
		}
		if(ans!=1e9)
		cout<<ans<<endl;
		else puts("-1");
	}

	return 0;
}

/// In the name of God

#include <bits/stdc++.h>

#define FILE_NAME "A"

using namespace std;
using ll = long long;

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define SZ(x) ((int) x.size())
#define all(x) x.begin(), x.end()
#define what_is(x) cerr << #x << " is " << x << endl;

void freekick() {
#ifndef ONLINE_JUDGE
    freopen(FILE_NAME".in", "r", stdin);
    freopen(FILE_NAME".out", "w", stdout);
#endif
}

const ll INF = 2e9 + 6;
const int N = 1e5 + 123;
const int DX[] = {+1, 0, -1, 0, +1, +1, -1, -1};
const int DY[] = {0, +1, 0, -1, +1, -1, +1, -1};

void freegoal() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

//ll pref[N];

int jeck(vector<int> &a, int x, int y) {
    return !x ? a[y] : (a[y] ^ a[x - 1]);
}

signed main() {
    freekick();
    freegoal();
    int n;
    cin >> n;
    vector<int> a(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i < n; i++)
        a[i] = a[i] ^ a[i - 1];
    if (n > 80)
        return cout << 1, 0;
    /*auto lo  = [&](vector<int> &a, int x, int y) -> int {
        if (!x)
            return a[y];
        else
            return (a[y] ^ a[x - 1]);
        return !x ? a[y] : (a[y] ^ a[x - 1]);
    };*/
    int answer = INT_MAX;
    for (int lock = 0; lock < n - 1; lock += 1) {
        for (int i = lock; i >= 0; i -= 1) {
            for (int j = lock + 1; j < n; j += 1) {
                int d = jeck(a, i, lock);
                int q = jeck(a, lock + 1, j);
                if (d > q) {
                    int sum = (j - (lock + 1)) + (lock - i);
                    answer = min(answer, sum);
                 }
            }
        }
    }
    if (answer == INT_MAX)
        cout << -1 << "\n";
    else
        cout << answer << "\n";
    return false;
}

/**
 * @author yuzining
 * @date 2020/11/29 15:46
 */

#ifdef local
#include "D:\VSCODE\local.hpp"
#else
#include<bits/stdc++.h>
using namespace std;
#define debug(...) do { } while(0)
void Main();
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
  return 0;
}
#endif

int a[100005];
int b[100005];

void Main() {
  int n; cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = b[i - 1] ^ a[i];
  }
  a[n + 1] = INT_MAX;
  if (n > 100) {
    cout << 1 << '\n';
    return;
  }
  int ans = INT_MAX;
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      for (int k = j + 1; k <= n; k++) {
        if ((b[j] ^ b[i - 1]) > (b[k] ^ b[j])) {
          ans = min(ans, k - i - 1);
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if ((b[j] ^ b[i - 1]) > a[j + 1]) {
        ans = min(j - i, ans);
      }
      if ((b[j] ^ b[i - 1]) < a[i - 1]) {
        ans = min(j - i, ans);
      }
    }
  }
  if (ans == INT_MAX) {
    cout << -1 << '\n';
  } else {
    cout << ans << '\n';
  }
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#pragma GCC optimize ("-O3")
#define int long long
#define ld long double
#define endl "\n"

#define rep(i,begin,end) for (__typeof(end) i=begin-(begin>end); i!=(end)-(begin>end); i+=1-2*(begin>end))
#define umap unordered_map
#define pq priority_queue
#define pb push_back
#define mp make_pair
#define fs first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define mii map<int,int>
#define pii pair<int,int>
#define vc vector
#define vi vc<int>
#define vvi vc<vi>
#define all(v) v.begin(),v.end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define w(t) int t; cin>>t; rep(tc,0,t)
#define clr(a,x) memset(a,x,sizeof a)

#define chkbit(x,i) ((x)&(1LL<<(i)))
#define setbit(x,i) ((x)|(1LL<<(i)))
#define setbits(x)  __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define print(a, n) rep(i,0,n) cout<<a[i]<<" "; cout<<endl;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int mod = 1e9+7;
const int mod2 = 998244353;
const int N = 2e6;
const int inf = 1e18;
const ld PI = 3.141592653589793;

//=====================================================

template<typename... T>
void in(T&... args) {((cin>>args), ...);}
template<typename... T>
void out(T&&... args) {((cout<<args<<" "), ...);}
template<typename... T>
void outln(T&&... args) {((cout<<args<<" "), ...); cout<<endl;}

int nxt(){int x;cin>>x;return x;}
int add(int a,int b,int mod){int res=(a+b)%mod;return (res<0)?res+mod:res;}
int mul(int a,int b,int mod){int res=(a*1LL*b)%mod;return (res<0)?res+mod:res;}
int range(int x,int y,int z) {return (x >= y && x <= z);}

struct customCompare {
    bool operator () (int x, int y) {
        return x>y;
    }
};

//=====================================================

void solve() {
    int n = nxt();
    int a[n];

    rep (i, 0, n)
        cin >> a[i];

    if (n <= 60) {
        int ans = inf;
        for (int i = 0; i < n; i++) {
            int x = 0;

            for (int j = i; j >= 0; j--) {
                x = x ^ a[j];
                int y = 0;

                for (int k = i+1; k < n; k++) {
                    y = y ^ a[k];

                    if(x > y) {
                        ans = min(ans, k-j-1);
                    }
                    if (k+1 < n && y > a[k+1])
                        ans = min(ans, k-i-1);
                }

                if (j-1 >= 0 && x < a[j-1])
                    ans = min(ans, i-j);
            }
        }

        if(ans == inf) ans = -1;
        cout << ans << endl;
        return;
    }

    cout << 1 << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    assert(freopen("input.txt", "r", stdin));
    // assert(freopen("output.txt", "w", stdout));
    #endif

    solve();
    // int t; cin >> t;
    // for (int tc = 1; tc <= t; tc++) {
    //     cout << "Case #" << tc << ": ";
    //     solve();
    // }

    // printclock;
    return 0;
}

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto& x : a) cin >> x;
  vector<int> p(n + 1);
  for (int i = 0; i < n; i++) {
    p[i + 1] = p[i] ^ a[i];
  }
  for (int len = 3; len <= n; len++) {
    for (int st = 0; st <= n - len; st++) {
      for (int i = st + 1; i < st + len; i++) {
        int x = p[i] ^ p[st];
        int y = p[st + len] ^ p[i];
        if (x > y) {
          cout << len - 2 << endl;
          return 0;
        }
      }
    }
  }
  cout << -1 << endl;
  return 0;
}

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <fstream>
#include <queue>
#include <iomanip>
#include <string>

using namespace std;

#define ll long long
#define endl '\n'
#define BE(v) v.begin(), v.end()

const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int bes = 2e9;

int a[N];
int l[N];

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	int pow = 1;
	for (int i = 0; i < n; i++)
	{
		while (pow * 2 <= a[i])
		{
			pow *= 2;
		}
		l[i] = pow;
	}
	for (int i = 0; i < n - 2; i++)
	{
		if ((l[i] == l[i + 1]) && (l[i + 1] == l[i + 2]))
		{
			cout << 1;
			return 0;
		}
	}
	int ans = bes;
	for (int i = 0; i < n; i++)
	{
		for (int j = i; j < n; j++)
		{
			int now = 0;
			for (int u = i; u <= j; u++)
			{
				now ^= a[u];
			}
			if (((i > 0) && (now < a[i - 1])) || ((j < n - 1)&&(now > a[j + 1])))
			{
				ans = min(ans, j - i);
			}
			for (int k = j + 1; k < n; k++)
			{
				int nnow = 0;
				for (int u = j + 1; u <= k; u++)
				{
					nnow ^= a[u];
				}
				if (now > nnow)
				{
					ans = min(ans, (j - i) + (k - j - 1));
				}
			}
		}
	}
	if (ans == bes)
	{
		cout << -1;
	}
	else
	{
		cout << ans;
	}
}

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include "bits/stdc++.h"
using namespace std;

#define all(x) (x).begin(), (x).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define un_map unordered_map
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define rrep(i,a,n) for (int i = a; i >= n; --i)
#define irep(i,a,n,inc) for (int i = a; i < n; i += inc)
#define endl "\n"

typedef long long ll;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define int long long

long long power_mod(long long a, long long b, long long mo) {
   long long ans = 1;
   while (b) {
      if(b & 1) {
          ans = (ans % mo * a % mo) % mo;
      }
      a = (a % mo * a % mo) % mo;
      b /= 2;
   }
   return ans;
}

int const nax = 2e5 + 1;
int v[nax];
int rights[nax];

int32_t main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int n; cin >> n;

   for (int i = 0; i < n; ++i) cin >> v[i];
   auto right_call = [&](int val)->int{
      for (int i = 29; i >= 0; --i) {
         if ((val >> i) & 1) return i;
      }
      return 0;
   };

   for (int i = 0; i < n; ++i) rights[i] = right_call(v[i]);

   int ans = 1e12;
   for (int i = 1; i < n - 1; ++i) {
      if (rights[i - 1] == rights[i] && rights[i] == rights[i + 1]) {
         cout << 1;
         return 0;
      }
   }
   for (int i = 0; i < n; ++i) {
      int a = 0;
      for (int j = i - 1; j >= 0; --j) {
         a = (a ^ v[j]);
         int p = 0;
         for (int k = i; k < n; ++k) {
            p = (p ^ v[k]);
            if (a > p) {
               ans = min(ans, k - j - 1);
            }
         }
      }
   }
   cout << ((ans >= 1e9)?-1:ans);
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define float long double
#define pie 3.1415926536
#define pb push_back
#define N 998244353
#define M 998244353
#define ff first
#define ss second
#define INT_MAX LLONG_MAX
#define pi pair<int,int>
#define pii pair< int, pair<int,int> >
#define all(v) (v).begin(),(v).end()
#define mem(a,b) memset(a,b,sizeof(a))
void solve(){
	int n;
	cin>>n;
	map<int,int> m;
	int a[n+5];
	for(int i=1; i<=n ;i++){
		cin>>a[i];
	}
	for(int i=1; i<=n ;i++){
		for(int j=32; j>=0 ;j--){
			if((a[i]>>j)&1){
				m[j]++;
				break;
			}
		}
	}
	for(int i=0; i<=32 ;i++){
		if(m[i] > 2) {
			cout<<"1\n";
			return;
		}
	}
	int Xor[n+5] = {0};
	for(int i=1; i<=n ;i++){
		Xor[i] = Xor[i-1]^a[i];
	}
	int ans = INT_MAX;
	for(int i=1; i<=n ;i++){
		for(int j=i+1; j<=n ;j++){
			for(int k=i; k<=j-1 ;k++){
				if((Xor[k]^Xor[i-1]) > (Xor[j]^Xor[k])){
					ans = min(ans,j-i-1);
				}
			}
		}
	}
	if(ans == INT_MAX) cout<<"-1\n";
	else cout<<ans<<endl;
}
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t;
//	cin>>t;
	t = 1;
	for(int T=1; T<=t ;T++){
		solve();
	}
}

#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define cerr cout
#define endl '\n'

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)

#define debarr(a, n) cerr << #a << " : "; for(int i = 0; i < n; i++) cerr << a[i] << " "; cerr << endl;
#define debmat(mat, row, col) cerr << #mat << " :\n"; for(int i = 0; i < row; i++){for(int j = 0; j < col; j++) cerr << mat[i][j] << " "; cerr << endl;}

typedef long long ll;
const ll MOD = 1000000007;

ll binpow(ll b, ll p){ ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % MOD; b = (b * b) % MOD; p >>= 1;}return ans;}
ll modinv(ll x){return binpow(x, MOD - 2);}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	ll n, i, l, r, mid, a1, a2, x, c, ans = 1e9;
	cin >> n;
	vector<ll> a(n), bits(n, 0);
	for(i = 0; i < n; i++)
	{
		cin >> a[i];
		x = a[i];
		c = 0;
		while(x)
		{
			c++;
			x /= 2;
		}
		bits[i] = c;
	}
	// pr(bits);
	for(i = 1; i < n - 1; i++)
	{
		if(bits[i] == bits[i - 1] && bits[i] == bits[i + 1])
		{
			cout << 1;
			return 0;
		}
	}
	for(l = 0; l < n; l++)
	{
		for(r = l + 1; r < n; r++)
		{
			for(mid = l; mid <= r; mid++)
			{
				// pr(l, r, mid);
				a1 = a2 = 0;
				for(i = l; i < mid; i++)
					a1 ^= a[i];
				for(i = mid; i <= r; i++)
					a2 ^= a[i];
				// pr(a1, a2);
				if(a1 > a2)
					ans = min(ans, r - l - 1);
			}

		}
	}
	cout << (ans < 1e9 ? ans : -1);
}

#include<bits/stdc++.h>
using namespace std;
int n,a[100005];
int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
        cin>>a[i];
    int ans=1000;
    for (int i=1;i<=n;i++)
    {
        int tmp=0;
        for (int j=0;j<min(i,30);j++)
        {
            tmp^=a[i-j];
            int tmpp=0;
            for (int k=0;k<min(n-i,30);k++)
            {
                tmpp^=a[i+1+k];
                if (tmp>tmpp) ans=min(ans,j+k);
            }
        }
    }
    if (ans==1000) puts("-1");
    else cout<<ans;
}

#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include <map>
#include <string>
#include <algorithm>
#include <iomanip>
#include <set>
#include <unordered_set>
#include <deque>
#include <functional>
#include <queue>
#include <cmath>
#include <array>

#define int long long
//#define endl '\n'
using namespace std;

const int INF = 1e18;
int a, b, c, d, e, p = 1e9 + 7, q, t, f;
int debug = 0;
string s;
set<pair<int, int>> set1;
int mas[200000];
int gcd(int a, int b) {
	while (a && b) {
		if (a > b) {
			a %= b;
		}
		else {
			b %= a;
		}
	}
	return a + b;
}
map<int, vector<int>> mp;
vector<int> vec, vec2, vec3, vec4;

const int MAXN = 3e5;
int arr[MAXN];
int lft[MAXN], rgh[MAXN];
int used[MAXN];

signed main() {
	ios_base::sync_with_stdio(false);
	srand(5757);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	if (n > 120) {
		cout << 1;
		return 0;
	}
	int res = INF;
	for (int i = 0; i < n; i++) {
		for (int j = i; j < n; j++) {
			for (int i2 = j + 1; i2 < n; i2++) {
				int ans1 = 0, ans2 = 0;
				for (int k = i; k <= j; k++) {
					ans1 = (ans1 ^ arr[k]);
				}
				for (int k = j + 1; k <= i2; k++) {
					ans2 = (ans2 ^ arr[k]);
				}
				if (ans1 > ans2) {
					res = min(res, i2 - i - 1);
				}
			}
		}
	}
	if (res > 1e9) {
		cout << -1;
		return 0;
	}
	cout << res;
	cin >> a;
	return 0;
}

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include "bits/stdc++.h"
using namespace std;

#define all(x) (x).begin(), (x).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define un_map unordered_map
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define rrep(i,a,n) for (int i = a; i >= n; --i)
#define irep(i,a,n,inc) for (int i = a; i < n; i += inc)
#define endl "\n"

typedef long long ll;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define int long long

long long power_mod(long long a, long long b, long long mo) {
	long long ans = 1;
	while (b) {
		if(b & 1) {
			 ans = (ans % mo * a % mo) % mo;
		}
		a = (a % mo * a % mo) % mo;
		b /= 2;
	}
	return ans;
}

void solve() {

}

int32_t main() {
	ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int n; cin >> n;
   vector<int> v(n);
   for (int i = 0; i < n; ++i) cin >> v[i];
   int ans = 1e12;
   for (int i = 1; i < n - 1; ++i) {
		if ((v[i] ^ v[i - 1]) > v[i + 1]) {
			ans = 1;
		}
		int d = (v[i]  ^ v[i + 1]);
		if (i - 2 >= 0) {
			int y = (v[i - 1] ^ v[i + 1]);
			if (i + 2 < n && (d ^ y) > v[i + 2]) {
				ans = 2;
			}
		}
	}
   cout << ((ans >= 1e9)?-1:ans);
}

	//for (int i = 0; i < n; ++i) {
		//cout << rights[i] << " ";
	//}
	//cout << endl;
	//for (int i = 0; i < n; ++i) {
		//cout << dp[i] << " ";
	//}
	//cout << endl;
	//for (int i = 0; i < n; ++i) {
		//cout << value[i] << " ";
	//}
	//cout << endl;
	//cout << endl;

#include<bits/stdc++.h>
using namespace std;

int n,Ans;

int A[100005];

inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){
       if(ch=='-')f=-1;
       ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
       x=(x<<1)+(x<<3)+ch-'0';
       ch=getchar();
    }
    return x*f;
}

int main(){

    n=read();

    for(register int i=1;i<=n;++i)
        A[i]=read();

    if(n>100){
        printf("%d\n",1);
        return 0;
    }

    A[0]=-INT_MAX;

    Ans=INT_MAX;
    for(register int i=3;i<=n;++i){
        int sum=A[i-1];
        for(register int j=i-2;j;--j){
            sum^=A[j];
            if(sum>A[i]||sum<A[j-1]){
                Ans=min(Ans,i-j-1);
                break;
            }
        }
    }

    printf("%d\n",Ans==INT_MAX?-1:Ans);

    return 0;
}

#include<bits/stdc++.h>
#define N 1000010
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;
const ll mod=998244353;
int n;
ll a[N];
int ans=inf;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%lld",&a[i]);
	}
	if(n==2){
		printf("-1\n");
		return 0;
	}
	for(int i=3;i<=n;++i)
	{
		if((a[i-2]^a[i-1])>a[i]){
			printf("1\n");
			return 0;
		}
	}
	for(int i=3;i<=n;++i)
	{
		int num=a[i-1];
		for(int k=i-2;k>=1;--k)
		{
			num^=a[k];
			if(num>a[i]){
				ans=min(ans,i-k-1);
			}
		}
	}
	for(int i=1;i<=n-2;++i)
	{
		int num=a[i+1];
		for(int k=i+2;k<=n;++k)
		{
			num^=a[k];
			if(num>a[i]){
				ans=min(ans,k-i-1);
			}
		}
	}
	for(int i=3;i<=n;++i)
	{
		int num=a[i-1],r=a[i];
		for(int k=i-2;k>=1;--k)
		{
			num^=a[k];
			for(int j=i+1;i<=n;++i)
			{
				r^=a[j];
				if(num>r){
					ans=min(ans,i-k-1+j-i);
				}
			}
		}
	}
	if(ans==inf) printf("-1\n");
	else printf("%d\n",ans);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define fi first
#define se second
#define pb push_back
#define trash trash
#define ALL(x) x.begin(),x.end()
const int oo=1e9;
const int Mod=1e9+7;
const long long OO=1e18;
const int N=1e5+5;
int n, a[N], x[N];
///////////////////1112<3/////////////////
void in()
{
  cin >> n ;
  for(int i=1; i<=n; i++)cin >> a[i];
  for(int i=2; i<=n; i++)
  {
    if(i<n && (a[i]^a[i-1])>a[i+1])
    {
      cout << 1 <<'\n';
      exit(0);
    }
    if(i>2 && (a[i]^a[i-1]) < a[i-2])
    {
      cout << 1 <<'\n';
      exit(0);
    }
  }
}
void pro(int t)
{
  for(int i=t; i<=n; i++)
    {
      int val = x[i]^x[i-t];
      if(i<n && val>a[i+1])
      {
        cout << t <<'\n';
        exit(0);
      }
      if(i>t && val < a[i-t])
      {
        cout << t <<'\n';
        exit(0);
      }
    }
}
void solve()
{
  if(n>3)
  {
    for(int i=3; i<=n; i++)
    {
      int val = a[i]^a[i-1]^a[i-2];
      if(i<n && val>a[i+1])
      {
        cout << 2 <<'\n';
        exit(0);
      }
      if(i>3 && val < a[i-3])
      {
        cout << 2 <<'\n';
        exit(0);
      }
    }
  }
  for(int i=1; i<=n; i++)x[i] = x[i-1]^a[i];
  for(int i=4; i<min(n,100); i++)pro(i);
  cout << -1;
}
///////////////////1112<3/////////////////
void file()
{
  if(fopen("trash.inp", "r"))
      freopen("trash.inp", "r", stdin), freopen("trash.out", "w", stdout);
    // else freopen("trash.inp", "r", stdin), freopen("trash.out", "w", stdout);
}
int main()
{
  file();
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  in();
  solve();
}

#include <bits/stdc++.h>

using namespace std;
const int MAXN = 100100;
int n, a[MAXN];

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	for(int i = 2; i <= n - 1; ++i)
	{
		if(__lg(a[i - 1]) == __lg(a[i]) && __lg(a[i]) == __lg(a[i + 1]))
			printf("1\n"), exit(0);
	}
	int ans = n;
	for(int i = 2; i < n; ++i)
	{
		if(__lg(a[i]) == __lg(a[i - 1]))
			continue;
		int x = a[i];
		for(int j = 1; i - j >= 1; ++j)
		{
		       x ^= a[j];
		       if(x > a[i + 1])
			       ans = min(ans, j);
		}
	}
	printf("%d\n", ans == n ? -1 : ans);
}

#include<bits/stdc++.h>
using namespace std;
template <class T> ostream &operator << (ostream &os, const vector<T> &p) { os << "["; for (auto&it : p) os << it << " "; return os << "]";}
template <class S, class T> ostream &operator << (ostream &os, const pair<S, T> &p) { return os << "(" << p.first << "," << p.second << ")";}
#ifndef ONLINE_JUDGE
#define deb(...) dbs(#__VA_ARGS__,__VA_ARGS__)
template <class T> void dbs(string str, T t) { cerr << str << ":" << t << "\n";}
template<class T, class...S> void dbs(string str, T t, S... s) { int idx = str.find(','); cerr << str.substr(0, idx) << ":" << t << ","; dbs(str.substr(idx + 1), s...);}
#else
#define deb(...){}
#endif
#define int long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < n; i++)
#define sz(x) (int)x.size()
#define nl cout<< '\n'
#define pr(x) {cout << x << "\n"; return;}
#define all(x) x.begin(), x.end()
#define re(i,n) for(int i = 1; i <= n; i++)
#define ini(x, y) memset(x, y, sizeof(x))
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int N = 2e5 + 10;

void solve() {
	int n; cin >> n;
	if (n > 60) pr(-1);
	int a[n + 1]; rep(i, n) cin >> a[i];
	if (n == 2) pr(-1);
	re(i, n - 1) {
		int x = a[i] ^ a[i + 1];
		if (i + 2 <= n && x > a[i + 2]) pr(1);
		if (i - 1 >= 1 && x < a[i - 1]) pr(1);
	}
	int dp[70][70], pre[70][70];
	rep(i, 70) {
		rep(j, 70) dp[i][j] = 1e16, pre[i][j] = a[i];
	}
	rep(i, n) {
		dp[i][i] = a[i]; pre[i][i] = a[i];
	}
	for (int i = n - 2; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			for (int k = i; k < j; k++) {
				umin(dp[i][j], dp[i][k]^dp[k + 1][j]);
			}
		}
	}
	for (int i = 1; i < n; i++) {
		for (int j = i - 1; j >= 0; j--) {
			for (int k = j; k < i; k++) {
				umin(pre[j][i], pre[j][k]^pre[k + 1][i]);
			}
		}
	}
	int ans = 1e9;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= i; j++) {
			for (int k = i + 1; k < n; k++) {
				if (dp[j][i] > dp[i + 1][k]) umin(ans, i - j + k - i - 1);
			}
		}
	}
	if (ans == 1e9) ans = -1;
	pr(ans+1);
}

signed main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	while (q--) solve();
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int setBitNumber(int n)
{
    n |= n >> 1;
    n |= n >> 2;
    n |= n >> 4;
    n |= n >> 8;
    n |= n >> 16;
    n = n + 1;
    return (n >> 1);
}
void solve()
{
    int n;
    cin >> n;
    vector<int> v(n), p(n);
    vector<int> to_check;

    int flag = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        p[i] = setBitNumber(v[i]);

        if (i >= 2)
            if (p[i - 1] == p[i])
                flag = 1, to_check.push_back(i);

        if (i >= 2)
            if (p[i - 2] == p[i - 1] && p[i - 1] == p[i])
            {
                cout << 1;
                return;
            }
    }
    if (flag == 0)
    {
        cout << -1;
        return;
    }
    // for (auto it : p)
    //     cout << it << ' ';
    int ans = INT_MAX;
    for (int i : to_check)
    {
        for (int j = i - 2; j >= 0; j--)
        {
            int sor1= 0 , sor2 = v[i]^v[i-1];
            for (int k = j; k <= i-2; k++)
            {
                sor2 ^= v[k];
            }
            if(sor1 > sor2)ans = min(ans, i-j-1);
            for(int k=i-2; k > j;k--){
                sor1 ^= v[k];
                sor2 ^= v[k];
                if(sor1 > sor2)ans = min(ans, i-j-1);
            }
        }
    }
    cout << ((ans == INT_MAX) ? -1 : ans);
}

int main()
{
    ios::sync_with_stdio(false);
    solve();
}

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include "bits/stdc++.h"
using namespace std;

#define all(x) (x).begin(), (x).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define un_map unordered_map
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define rrep(i,a,n) for (int i = a; i >= n; --i)
#define irep(i,a,n,inc) for (int i = a; i < n; i += inc)
#define endl "\n"

typedef long long ll;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define int long long

long long power_mod(long long a, long long b, long long mo) {
	long long ans = 1;
	while (b) {
		if(b & 1) {
			 ans = (ans % mo * a % mo) % mo;
		}
		a = (a % mo * a % mo) % mo;
		b /= 2;
	}
	return ans;
}

int dp[200000 + 1];
int n;
string s;

void solve() {
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; ++i) cin >> v[i];
	auto right_call = [&](int val)->int{
		for (int i = 29; i >= 0; --i) {
			if ((val >> i) & 1) return i;
		}
		return 0;
	};
	vector<int> right(n);
	int ans = 1e9;
	for (int i = 0; i < n; ++i) right[i] = right_call(v[i]);
	//debug(right);
	for (int i = n - 1; ~i; --i) {
		for (int j = i - 1, p = 0, val = 0; ~j; --j, ++p) {
			if ((val ^ v[j]) < val) break;
			if ((val ^ v[j]) > v[i]) {
				ans = min(ans, p);
				break;
			}
			val = (val ^ v[j]);
		}
	}
	cout << ((ans == 1e9)?-1:ans) << endl;
}

int32_t main() {
	ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int tc = 1;
   while (tc--) {
		solve();
	}
}

#include <algorithm>
#include <iostream>
#include <cassert>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
using namespace std;
using ll = long long;
int a[100002], f[100002], xr[100002];
int cntf(int x)
{
	int q = 0;
	while (x)
	{
		x >>= 1;
		q++;
	}
	return q;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		f[i] = cntf(a[i]);
	}
	for (int i = 1; i < n - 1; i++)
	{
		if (a[i] == a[i + 1]) {
			cout << 1 << '\n'; return 0;
		}
		if (f[i] == f[i - 1] && f[i] == f[i + 1])
		{
			cout << 1 << '\n'; return 0;
		}
	}
	bool ok = false;
	int ans = 10'000'000;
	for (int i = 0; i < n - 1; i++)
	{
		if (f[i] == f[i + 1])
		{
			int xr = a[i];
			int cnt = 0;
			int t = i - 1;
			while (t >= 0)
			{
				xr ^= a[t];
				cnt++;
				if (xr > a[i + 1])break;
				t--;
			}
			if (xr > a[i + 1]) {
				ans = min(ans, cnt); ok = true;
			}
		}
	}
	if (ok)cout << ans << '\n';
	else cout << -1 << '\n';
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define umii            unordered_map<int,int >
#define umic            unordered_map<int,char >
#define umci            unordered_map<char,int >
#define usi             unordered_set<int>
#define usc             unordered_set<char>
#define mii             map<int,int >
#define mic             map<int,char >
#define mci             map<char,int >
#define si              set<int>
#define sc              set<char>
#define ll              long long
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vii             vector<vector<int>>
#define vi              vector<int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int>>
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
int32_t main()
{
   use_fast;
   ll n ;
   cin >> n ;
   ll arr[n];
   for(ll i = 0 ;i  < n ; i++){
       cin >> arr[i] ;
   }
   ll msb[n] ;
   for(ll i= 0 ; i < n ;  i++){
       ll num = log(arr[i]);
       msb[i] = num + 1 ;
   }
   bool ans = false ;
   for(ll i= 1 ; i <n -1 ; i++){
       if(msb[i]== msb[i-1] && msb[i] == msb[i+1]){
           ans = true ;
           break;
       }
   }
   if(ans)
    cout << 1 << endl ;
   else {
       ll pref[n] , suff[n];
       pref[0] = arr[0];
       suff[n-1] = arr[n-1] ;
       for(ll i = 1 ; i< n; i++){
           pref[i] = (pref[i-1] ^ arr[i]);
           suff[n-i-1] =(suff[n-i]^arr[n-i-1]);
       }
    //    for(ll i = 0 ; i < n ; i++){
    //        cout << pref[i] <<" " ;
    //    }
    //    cout << endl ;
    //     for(ll i = 0 ; i < n ; i++){
    //        cout << suff[i] <<" " ;
    //    }
    //    cout << endl ;
       ll ans = INT_MAX  ;
       for(ll i=0 ; i < n ; i++){
           for(ll j = i +1 ; j < n ; j++){
               if(pref[i] > suff[j]){
                   ans = min(ans , j - i   );
               }
               if(i!= n-1 && pref[i]> arr[i+1]){
                   ans = min(ans , i );
               }
            //    if(suff[j])
           }
       }
       if(ans == INT_MAX)
         cout << -1 << endl;
        else
         cout << ans << endl ;
   }

   return 0;
}

#include <iostream>
#include <deque>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#define int long long
using namespace std;
signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector <int> a;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        a.push_back(x);
    }
    for (int i = 2; i <= min(n,(long long) 50); ++i) {
        int k = i;
        int uk1 = 0;
        int uk2 = 0;
        int xo = 0;
        while (uk2 - uk1 < i) {
            xo = (xo ^ a[uk2]);
            uk2++;
        }
        if (uk2 != n) {
            if (xo > a[uk2]) {
                cout << i - 1;
                return 0;
            }
        }
        while (uk2 < n) {
            xo = (xo ^ a[uk2]);
            xo = (xo ^ a[uk1]);
            if (uk2+1 < n && a[uk2+1] < xo) {
                cout << i - 1;
                return 0;
            }
            if (uk1 > 0 && a[uk1] > xo) {
                cout << i - 1;
                return 0;
            }
            uk1++;
            uk2++;
        }
    }
    cout << -1;
}

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

void err(istream_iterator<string> it) {cout << '\n';}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    string s = typeid(a).name();
    cout << "[" << *it << " = ";
    cout << a;
    cout << "] ";
    err(++it, args...);
}

#define F first
#define S second
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pf push_front
#define db double
#define ld long double
#define ofk order_of_key
#define fbo find_by_order
#define ppb pop_back
#define ppf pop_front
#define br cout << '\n'
#define pll pair<long long, long long>
#define here cout << "HERE\n"
#define bruh cout << "BRUH\n"
#define all(x) (x).begin(),(x).end()
#define sqr(x) (x) * (x)
#define __ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define TEST int TT; cin >> TT; for(int T = 1; T <= TT; T++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int gcd(int a, int b) {if (a < b) swap(a, b); return b ? gcd(b, a % b) : a;}
ll gcd(ll a, ll b) {if (a < b) swap(a, b); return b ? gcd(b, a % b) : a;}

pair<int, int> dx[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

const int inf = 2e9 + 7;
const ll INF = 9e18 + 7;
//const ld pi = 3.1415926535897932384626433;
const db eps = 1e-6;
//const ld EPS = 1e-9;
int mod = 998244353;
const ll MOD = 1e15 + 7;

mt19937 lol(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 rofl(chrono::steady_clock::now().time_since_epoch().count());

//random_device random_device;
//mt19937 generator(random_device());

const bool multiple_tests = 0;
const int N = 1e6 + 7;

//#define int long long
#define pii pair<int, int>

int n, a[N], ans = inf;

void rec(vector<int> v, int t = 0) {
    if (v.size() == 1) return;
    for (int i = 0; i < v.size() - 1; i++) {
        int x = v[i] ^ v[i + 1];
        vector<int> cp(v);
        cp.erase(cp.begin() + i);
        cp[i] = x;
        if ((i && v[i - 1] > x) || (i + 2 < v.size() && v[i + 2] < x)) {
            ans = min(ans, t + 1);
            return;
        }
        rec(cp, t + 1);
    }
}

void solve() {
    vector<int> v;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        v.pb(a[i]);
    }
    if (v.size() <= 20) {
        rec(v);
        if (ans == inf) cout << -1;
        else cout << ans;
        return;
    }
    for (int i = 0; i < v.size() - 1; i++) {
        int x = v[i] ^ v[i + 1];
        if ((i && v[i - 1] > x) || (i + 2 < v.size() && v[i + 2] < x)) {
            cout << 1;
            return;
        }
        if ((i && v[i - 1] == x) || (i + 2 < v.size() && v[i + 2] == x)) {
            cout << 2;
            return;
        }
    }
    int ans = inf;
    for (int i = 2; i < n; i++) {
        int cur = 0;
        for (int j = i; j >= max(1, j - 100); j--) {
            cur ^= a[j];
            if (cur > a[i + 1]) {
                ans = min(ans, i - j);
            }
        }
    }
    if (ans == inf) ans = -1;
    cout << ans;
//    rep(q, 1, 10) {
//        vector<int> tmp;
//        for (int i = 1; i <= 50; i++) tmp.pb(i);
//        random_shuffle(all(tmp));
//        vector<int> v(tmp.begin(), tmp.begin() + 20);
//        sort(all(v));
//        ans = inf;
//        rec(v);
//        if (ans != 1) {
//            for (int el: v) cout << el << ' ';
//            cout << ": ";
//            cout << ans;
//            br;
//        }
//    }
}

/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?)
    * do smth instead of nothing and stay organized
    * WRITE STUFF DOWN
    * DON'T GET STUCK ON ONE APPROACH
*/

signed main() { __
//  freopen("cowland.in", "r", stdin);
//  freopen("cowland.out", "w", stdout);
    int TT = 1;
    if (multiple_tests) cin >> TT;
    for (int testcase = 1; testcase <= TT; testcase++) {
        solve();
        cout << '\n';
    }

//    #ifndef SSYernar
//      cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
//    #endif
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+2;
int nums[N];
int pre[N];

int main()
{
	int n;
	cin>>n;
	pre[0] = 0;
	for(int i=1;i<=n;i++){
		cin>>nums[i];
		pre[i] = pre[i-1]^nums[i];
	}
	int res = n;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			int tmp = pre[j]^pre[i-1];
			if(i>1&&tmp<nums[i-1]){
			    res = min(res,j-i);
			    break;
			}
			if(j<n&&tmp>nums[j+1]){
			    res = min(res,j-i);
			    break;
			}

		}
	}
	if(res<n)
	    cout<<res<<endl;
	else
	    cout<<-1<<endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long int
#define pb push_back
#define ff first
#define ss second
#define all(a) (a).begin(),(a).end()
#define vll vector<ll>
#define fl(i,a,b) for(ll i=a;i<=b;i++)
#define flr(i,a,b) for(ll i=a;i>=b;i--)
#define print(v) for(auto x: v) {cout<<x<<" ";} cout<<"\n";
#define keep_unique(v) sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
#define test() ll te; cin >> te; while(te--)
#define MOD  1000000007
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

const int N=1e6;

ll n,ans=1e16;
vll v(N),xv(N);

int main()
{
	cin>>n;
	fl(i,0,n-1) cin>>v[i];
	if(n>63)
	{
		cout<<1<<endl;
		return 0;
	}
	if(n==2)
	{
		cout<<-1<<endl;
		return 0;
	}
	v.insert(v.begin(),0);
	n+=2;
	v[n-1]=1e16;

	xv[0]=v[0];
	fl(i,1,n-1) xv[i]=v[i]^xv[i-1];
	fl(i,1,n-2)
	{
		fl(j,i+1,n-2)
		{
			fl(k,j+1,n-2)
			{
				ll x=xv[i-1]^xv[j],y=xv[j]^xv[k]; //db(i,j,k,x,y,v[i-1]);
				if(x<v[i-1]||x>y)
				{
					ans=min(ans,j-i+k-j-1);
				}
			}
		}
	}
	if(ans==1e16) ans=-1;
	cout<<ans<<endl;
}

#include<bits/stdc++.h>
#define ll long long
#define db double
#define mem(a) memset(a,0,sizeof(a))
const ll inf=1e18,maxn=1e5+5;
using namespace std;
ll read(){
   ll a=0,f=1;char c=getchar();
   while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
   while(c>='0'&&c<='9'){a=a*10+c-'0';c=getchar();}
   return a*f;
}
ll n,a[maxn],L[maxn],R[maxn],f[maxn];
int main(){
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=n;i++){
		for(int j=30;j>=0;j--){
			if(i>=(1<<j)){
				f[i]=j;break;
			}
		}
	}
	for(int i=1;i<=n;i++)L[i]=L[i-1]^a[i];
	for(int i=n;i>=1;i--)R[i]=R[i+1]^a[i];
	for(int i=1;i<=n-2;i++){
		if(f[i]==f[i+1]&&f[i+1]==f[i+2]){
			puts("1");
			return 0;
		}
	}
	for(int len=3;len<=n;len++){
		for(int st=1,ed;st+len-1<=n;st++){
			ed=st+len-1;
			for(int i=st;i<ed;i++){
				if((L[i]^L[st-1])>(R[i+1]^R[ed+1])){
					printf("%d\n",len-2);return 0;
				}
			}
		}
	}
	puts("-1");
	return 0;
}

// Author: Vinay Khilwani
// Language: C++

// @vok8: Codeforces, AtCoder, LeetCode, HackerEarth, TopCoder, Google, FB, CSES, Spoj, GitHub
// @vok_8: CodeChef, GFG
// @vok8_khilwani: HackerRank

// Never Stop Trying.
// Trying to be Better than Myself.

// while(true)
// {
//     if(AC)
//     {
//         break;
//     }
//     else if(Contest Over)
//     {
//         Try.
//         Check out Editorial.
//         Understand.
//         Find out your Mistake.
//         Learn the topic (if new).
//         Solve Problems on that topic (if new).
//         Upsolve that problem.
//         break;
//     }
//     else
//     {
//         Try.
//         Use Pen-Paper.
//         Find errors, edge cases, etc.
//         continue;
//     }
// }

// Optimizations
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#pragma GCC optimize("Os")

// Libraries
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

// Debugging
#define dbg(a) cerr<<a<<"\n";
#define debug_a(a) for(auto x:a) {cerr<<x<<" ";} cerr<<"\n";
#define debug_b(a) for(auto x:a) {cerr<<"["<<x.first<<", "<<x.second<<"]"<<"\n";} cerr<<"\n";
#define debug_c(a) for(auto x:a) {debug_a(x)} cerr<<"\n";
#define debug_d(a) for(auto x:a) {debug_b(x)} cerr<<"\n";
#define debug_e(a) cerr<<"["<<a.first<<", "<<a.second<<"]"<<"\n";

// Defines
#define fast ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL);
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define fr(i,a,n,b) for(int i=a; i<n; i+=b)
#define rfr(i,a,n,b) for(int i=a; i>=n; i-=b)
#define IN cin>>
#define OUT cout<<
#define nl "\n"
#define sz(a) int(a.size())
#define all(a) (a).begin(),(a).end()
#define each(a,b) for(auto &a:b)
#define pb push_back
#define set_bits(a) __builtin_popcountll(a)
#define ar array
#define write(a) for(auto x:a) {OUT x<<" ";} OUT endl;
#define read(a) for(auto &x:a) {IN x;}
// #define oset tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
using ll=long long int;
using ld=long double;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vi=vector<int>;
const ll mod=(ll)(1e9)+21LL;
const ll M=998244353LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ld pi=acos(-1);

// General Functions
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo) //Fast Power
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll get_rand(ll l, ll r)
{
    uniform_int_distribution<ll> uid(l,r);
    return uid(rng);
}
void vok()
{
    fast
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        freopen("error.txt","w",stderr);
    #endif
}

// Global Variables
const int mxN=int(1e5)+100;

// Solver Function(s)
void solve()
{
    int n;
    IN n;
    vll a(n);
    read(a)
    loop(i,0,n-1)
    {
        ll x=a[i]^a[i+1];
        if(i && x<a[i-1])
        {
            OUT 1<<nl;
            return;
        }
        if(i<n-2 && x>a[i+2])
        {
            OUT 1<<nl;
            return;
        }
    }
    vll pre_xor(n);
    loop(i,0,n)
    {
        if(i)
        {
            pre_xor[i]=pre_xor[i-1]^a[i];
        }
        else
        {
            pre_xor[i]=a[i];
        }
    }
    int ans=INT_MAX;
    loop(i,0,n)
    {
        loop(j,i+1,n)
        {
            loop(k,j+1,n)
            {
                loop(l,k+1,n)
                {
                    ll x1=pre_xor[j];
                    if(i)
                    {
                        x1^=pre_xor[i-1];
                    }
                    ll x2=pre_xor[l]^pre_xor[k-1];
                    if(x1>x2)
                    {
                        ans=min(ans,j-i+l-k+1);
                    }
                }
            }
        }
    }
    if(ans==INT_MAX)
    {
        ans=-1;
    }
    OUT ans<<nl;
}

// Main Function
int main()
{
    vok();
    int t=1;
    // IN t;
    while(t--)
    {
        solve();
    }
    return 0;
}

#include<bits/stdc++.h>
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 5;
int a[maxn];

int main(){
    IOS;
    int n, ans, now, cnt;
    cin >> n;
    ans = n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 3; i <= n; i++){
        now = a[i];
        cnt = i - 1;
        while(cnt != 1 && now >= a[cnt] && i - cnt - 1 <= ans){
            now ^= a[cnt--];
        }
        if(now < a[cnt]) ans = min(ans, i - cnt - 1);
    }
    for(int i = 1; i <= n - 2; i++){
        now = a[i];
        cnt = i + 1;
        while(cnt != n && now <= a[cnt] && cnt - i - 1 <= ans){
            now ^= a[cnt++];
        }
        if(now > a[cnt]) ans = min(ans, cnt - i - 1);
    }
    cout << (ans == n ? -1 : ans) << endl;
}

#include <bits/stdc++.h>
using namespace std;

char getch()
{
	static char buf[1 << 14], *p1 = buf, *p2 = buf;
	return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 14, stdin), p1 == p2) ? EOF : *p1++;
}

void read(int &x)
{
	x = 0;
	char c = getch();
	while(c < '0' || c > '9') c = getch();
	while(c >= '0' && c <= '9')
	{
		x = x * 10 + (c - '0');
		c = getch();
	}
}

int T;
int n, ans;
int a[100001], bit[100001];

int main()
{
	read(n);
	for(int i = 1; i <= n; ++i)
	{
		read(a[i]);
		int x = a[i];
		while(x)
		{
			bit[i]++;
			x >>= 1;
		}
	}
	// for(int i = 1; i <= n; ++i) cout << bit[i] << " ";cout << endl;
	ans = 1e9;
	for(int i = 1; i <= n - 2; ++i)
		if(bit[i] == bit[i + 1] && bit[i + 1] == bit[i + 2])
		{
			puts("1");
			break;
		}

	for(int i = n; i >= 1; --i)
	{
		for(int j = 1; j < i; ++j)
		{
			int now = 0;
			for(int k = j; k < i; ++k)
			{
				now = now ^ a[k];
			}
			if(now > a[i]) ans = min(ans, i - j - 1);
		}
	}

	if(ans == 1e9) puts("-1");
	else printf("%d", ans);
	return 0;
}

#include<bits/stdc++.h>
#define int long long
#define bug(x) cerr<<#x<<" = "<<x<<'\n'

using namespace std;
using ll = long long;

const int maxn = 200100;
const int inf = 1e18;

int N, A[maxn];
int S[maxn];

struct node {
  int nxt[2];
  int id;
  node() {
    fill(begin(nxt), end(nxt), -1);
    id = 0;
  }
};

vector<node> trie(1);

void add(int val, int pos) {
  int v = 0;
  for (int i = 30; i >= 0; --i) {
    int c = (val >> i & 1);
    if (trie[v].nxt[c] == -1) {
      trie[v].nxt[c] = (int)trie.size();
      trie.emplace_back();
    }
    trie[v].id = pos;
    v = trie[v].nxt[c];
  }
  trie[v].id = pos;
}

int go(int id) {
  int v = 0;
  for (int i = 30; i >= 0; --i) {
    if (v == -1) break;
    int a = (S[id] >> i & 1);
    int b = (A[id + 1] >> i & 1);
    if (b == 1 && a == 0) {
      if (trie[v].nxt[1] == -1) return -inf;
      v = trie[v].nxt[1];
    } else if (b == 1 && a == 1) {
      if (trie[v].nxt[0] == -1) return -inf;
      v = trie[v].nxt[0];
    } else if (b == 0 && a == 1) {
      if (trie[v].nxt[0] != -1) {
        v = trie[v].nxt[0];
        return trie[v].id;
      }
      v = trie[v].nxt[1];
    } else if (b == 0 && a == 0) {
      if (trie[v].nxt[1] != -1) {
        v = trie[v].nxt[1];
        return trie[v].id;
      }
      v = trie[v].nxt[0];
    }
  }
  return -inf;
}

int og(int id) {
  int v = 0;
  for (int i = 30; i >= 0; --i) {
    if (v == -1) break;
    int a = (S[id] >> i & 1);
    int b = (A[id - 1] >> i & 1);
    if (b == 0 && a == 0) {
      if (trie[v].nxt[0] == -1) return inf;
      v = trie[v].nxt[0];
    } else if (b == 0 && a == 1) {
      if (trie[v].nxt[1] == -1) return inf;
      v = trie[v].nxt[1];
    } else if (b == 1 && a == 0) {
      if (trie[v].nxt[0] != -1) {
        v = trie[v].nxt[0];
        return trie[v].id;
      }
      v = trie[v].nxt[1];
    } else if (b == 1 && a == 1) {
      if (trie[v].nxt[1] != -1) {
        v = trie[v].nxt[1];
        return trie[v].id;
      }
      v = trie[v].nxt[0];
    }
  }
  return inf;
}

signed main() {
//  freopen("cc.inp", "r", stdin);
//  freopen("cc.out", "w", stdout);
  ios::sync_with_stdio(0); cin.tie(0);
  cin >> N;
  for (int i = 1; i <= N; ++i) cin >> A[i];
  int Ans = inf;
  add(0, 0);
  for (int i = 1; i < N; ++i) {
    S[i] = S[i - 1] ^ A[i];
    add(S[i], i);
    Ans = min(Ans, i - go(i) - 1);
  }
  memset(S, 0, sizeof S);
  trie.clear();
  trie.emplace_back();
  add(0, N + 1);
  for (int i = N; i > 0; --i) {
    S[i] = S[i + 1] ^ A[i];
    Ans = min(Ans, og(i) - i - 1);
    add(S[i], i);
  }
  if (Ans > N - 1) Ans = -1;
  cout << Ans << '\n';
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
#include<string>
#include<array>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<numeric>
#include<deque>
#include<functional>
#include<cstring>

#define int long long
#define double long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define forn(n) for(int i = 0; i < n; ++i)
#define rforn(n) for(int i = n - 1; i >= 0; --i)
#define pii pair<int, int>
#define umn(a, b) a = min(a, b)
#define umx(a, b) a = max(a, b)
#define rp(p) cin >> p.first >> p.second

using namespace std;

const int INF = 1e17 + 17;
const int N = 1e5 + 17;
const int mod = 998244353;

void precalc() {

}

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (auto& a : a) cin >> a;
	int t = min(n, 500LL);
	for (int ans = 2; ans < t; ++ans) {
		int xr = 0;
		for (int i = 0; i < ans; ++i) xr ^= a[i];
		for (int i = ans; i < n; ++i) {
			if (a[i] < xr) {
				cout << ans - 1;
				return;
			}
			xr ^= a[i - ans];
			xr ^= a[i];
		}
	}
	cout << -1;
}

signed main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);

	cout << setprecision(10) << fixed;

	precalc();

	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
		//cout << "\n";
	}

	return 0;
}

/*
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
ordered_set -> less -> less_equal
ordered_set find_by_order(k) -> k element
ordered_set order_of_key(k) -> returns the number of elements in a set strictly smaller than k
*/
#include <bits/stdc++.h>
#include <random>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

//template<typename T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const long long maxn = 3e5 + 123;
const long long inf = 1e9 + 123;
const long long linf = 1e18 + 123;
const long long mod = 1e9 + 7;
const double eps = 1e-9;
const double pi = acos(-1);
int dx[8] = {0, 1, -1, 0, 1, -1, 1, -1};
int dy[8] = {1, 0, 0, -1, 1, 1, -1, -1};

int sz = 2, t[35][maxn], kol[maxn], a[maxn];

void ins(int x, int id){
    int v = 1;
    for (int i = 30; i >= 0; i --){
        int bitx = bool(x & (1 << i));
        if (t[bitx][v] == 0){
            t[bitx][v] = sz;
            sz++;
        }
        kol[v] = max(kol[v], id);
        v = t[bitx][v];
    }
    kol[v] = max(kol[v], id);
}

int f1(int cur, int ar){
    int v = 1, ans = -inf;
    for (int i = 30; i >= 0; i--){
        int bitcur = bool(cur & (1 << i));
        int bitar = bool(ar & (1 << i));
        int nxt = 0;
        if (bitcur == 0 && bitar == 0){
            if (kol[t[1][v]]){
                ans = max(ans, kol[t[1][v]]);
            }
            nxt = t[0][v];
        }
        if (bitcur == 0 && bitar == 1){
            nxt = t[1][v];
        }
        if (bitcur == 1 && bitar == 0){
            if (kol[t[0][v]]){
                ans = max(ans, kol[t[0][v]]);
            }
            nxt = t[1][v];
        }
        if (bitcur == 1 && bitar == 1){
            nxt = t[0][v];
        }
        if (nxt == 0){
            break;
        }
        v = nxt;
    }
    return ans;
}

int f(int cur, int al){
    int v = 1, ans = inf;
    for (int i = 30; i >= 0; i--){
        int bitcur = bool(cur & (1 << i));
        int bital = bool(al & (1 << i));
        int nxt = 0;
        if (bitcur == 0 && bital == 0){
            nxt = t[0][v];
        }
        if (bitcur == 1 && bital == 0){
            nxt = t[1][v];
        }
        if (bitcur == 0 && bital == 1){
            if (kol[t[0][v]]){
                ans = min(ans, kol[t[0][v]]);
            }
            nxt = t[1][v];
        }
        if (bitcur == 1 && bital == 1){
            if (kol[t[1][v]]){
                ans = min(ans, kol[t[1][v]]);
            }
            nxt = t[0][v];
        }
        if(nxt == 0){
            break;
        }
        v = nxt;
    }
    return ans;
}

int main(){
    //freopen("input.cpp", "r", stdin);
    //freopen("output.cpp", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
    }
    ins(0, 0);
    int ans = inf, cur = 0;
    for (int r = 1; r < n; r++){
        cur = (cur ^ a[r]);
        ans = min(ans, r - f1(cur, a[r + 1]) - 1);
        if (cur > a[r + 1]){
            ans = min(ans, r - 1);
        }
        ins(cur, r);
    }
    memset(t, 0, sizeof(t));
    memset(kol, 0, sizeof(kol));
    sz = 2;

    ins(cur, n + 1);
    for (int l = n; l >= 1; l--){
        cur = (cur ^ a[l]);
        ans = min(ans, f(cur, a[l - 1]) - l - 1);
        //cout << l << " " << f(cur, a[l - 1]) - l - 1 << " 1\n";
        if (cur < a[l - 1]){
            ans = min(ans, n - l - 1);
            //cout << l << " " << n - l - 1 << " 2\n";
        }
        ins(cur, l);
    }
    if (ans > n - 1){
        ans = -1;
    }
    cout << ans;
    exit(0);
}

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <math.h>
#include <array>
#include <functional>
#include <numeric>
#include <algorithm>
#include <bitset>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;

#define LL_MAX 9223372036854775807
#define LL_MIN -9223372036854775806
#define read(to, thresh) for(int i=0; i < thresh; ++i) cin >> to[i];
#define all(x) x.begin(), x.end()

template<class T>
void smin(T &a, T b) {a = min(a, b);}
template<class T>
void smax(T &a, T b) {a = max(a, b);}
template<class T>
void print(vector<T> &a, string sep) {for(T el: a) cout << el << sep; cout << endl;}

void solve() {
    int n; cin >> n;
    vll a(n); read(a, n);
    if(n < 3) {
        cout << -1 << endl; return;
    }
    for(int i=0; i<n-1; i++) {
        if(i != n-2) {
            if((a[i] ^ a[i+1]) > a[i+2]) {
                cout << 1 << endl;
                return;
            }
        }
        if(i != 0) {
            if((a[i] ^ a[i-1]) < a[i-2]) {
                cout << 1 << endl; return;
            }
        }
    }
    if(n == 3) {
        cout << -1 << endl; return;
    }
    for(int i=1; i<n-2; i++) {
        ll x = (a[i] ^ a[i-1]) ^ a[i+1];
        if(i != 1) {
            if(x < a[i-2]) {
                cout << 2 << endl;
                return;
            }
        }
        if(i != n-2) {
            if(x > a[i+2]) {
                cout << 2 << endl;
                return;
            }
        }
    }
    cout << -1 << endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // int t; cin >> t;

    // while(t--) {
        solve();
    // }
}

// Author : heyuhhh
// Created Time : 2020/11/29 15:37:57
#include<bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;
void run() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<ll> pre(n + 1);
    for (int i = 0; i < n; i++) {
        pre[i + 1] = (pre[i] ^ a[i]);
    }
    vector<ll> suf(n + 2);
    for (int i = n; i >= 0; i--) {
        suf[i] = (suf[i + 1] ^ a[i - 1]);
    }
    for (int j = 1; j < 100; j++) {
        for (int i = 0; i + j < n; i++) {
            int k = i + j;
            ll now = (pre[k + 1] ^ pre[i]);
            if (i && now < a[i - 1]) {
                cout << j << '\n';
                return;
            }
            if (k + 1 < n && now > a[k + 1]) {
                cout << j << '\n';
                return;
            }
        }
    }
    for (int i = 1; i < n; i++) {
        if (pre[i] > suf[i + 1]) {
            cout << n - 2 << '\n';
            return;
        }
    }
    cout << -1 << '\n';
}
int main() {
#ifdef Local
    freopen("input.in", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define FOE(i, s, t) for (int i = s; i <= t; i++)
#define FOR(i, s, t) for (int i = s; i < t; i++)
#define FOD(i, s, t) for (int i = s; i >= t; i--)

#define LL long long
#define mp make_pair
#define pb push_back

#define K 120001
#define M 1 << 30

int n, a[K], t[K];

int main() {
	scanf("%d", &n);

	FOE(i, 1, n) scanf("%d", &a[i]);
	FOE(i, 1, n) t[i] = t[i - 1] ^ a[i];

	FOE(i, 1, n - 1) {
		int w = a[i] ^ a[i + 1];

		if (i > 1 && w < a[i - 1]) {
			puts("1");
			return 0;
		}

		if (i < n - 1 && w > a[i + 2]) {
			puts("1");
			return 0;
		}
	}

	int ret = n + n;

	FOE(i, 1, n) FOE(j, i + 1, n) FOE(k, j + 2, n) {
		int z1 = t[j] ^ t[i - 1];
		int z2 = t[k] ^ t[j];

		if (z1 > z2) {
			ret = min(ret, k - i - 1);
		}
	}

	if (ret > n) puts("-1");
	else printf("%d\n", ret);
}

#include<iostream>
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
#include<string>
#include<cstring>
#include<ctype.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,
			tree_order_statistics_node_update>
	new_data_set;
//   <<implemented_sorted_vector>>  new_data_set p;
//   <<insert_like_set>>           insert(key):log(n)
//<<accessing_iterator_by_index>> find_by_order(idx):log(n)
//	    <<accessing_by_value>>   order_of_key(key):log(n)
// << replace less<int> by greater<int> for descending order>>
// find(key), erase(find(key)) works the same!
typedef long long ll;
typedef long l;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ERR(x) cout<<"#x:"<<x<<endl
#define ERR2(x,y) cout<<"#x:"<<x<<" "<<"#y:"<<y<<endl;
#define ERR3(x,y,z) cout<<"#x:"<<x<<" "<<"#y:"<<y<<" "<<"#z:"<<z<<endl;
#define show(v) for(auto e: v) cout<<e<<" ";
#define showArr(A,n) for(int i=0;i<n;i++) cout<<A[i]<<" ";
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define umpit unordered_map<ll,ll>::iterator
#define mpit map<ll,ll>::iterator
#define setit set<ll>::iterator
#define all(v) v.begin(),v.end()

int bitly(ll n){
	int c = 0;
	while(n > 0) n = n>>1LL,c++;
	return c-1;
}

int main()
{
	int t;
	t = 1;
	int Case = 0;
	while(t--)
	{
		ll n;
		cin>>n;
		vector<ll>v(n),b(n);
		FOR(i,0,n){
			cin>>v[i];
			b[i] = bitly(v[i]);
		}
		//O(n)
		int flag = 0;
		FOR(i,1,n-1){
			if(b[i-1] == b[i] && b[i+1] == b[i]){
				flag = 1;
				break;
			}
		}
		if(flag == 1){
			cout<<1<<endl;
			continue;
		}
		// else other case O(n*n) implementation
		flag = 0;
		ll best = MOD;
		for(ll i=2;i<n;i++){
			ll j = i-1;
			ll val = 0;
			for(j;j>=0;j--){
				val = val^v[j];
				if(val > v[i]){
					flag = 1;
					best = min(best,i-j);
					break;
				}
			}
		}
		if(best == MOD){
			cout<<-1<<endl;
		} else {
			cout<<best-1<<endl;
		}

	}
	return 0;
}

#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
using namespace std;

int main(){

    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=INT_MAX;

    if (n>62){int ans=1;}
    else{

        for(int i=2;i<n;i++){
            int j=i-2;
            int cnt=0;
            int num=a[i-1];
            while (~i){
                num=num^a[j];
                j--;cnt++;
                if (num>a[i]){ans=min(ans,cnt);break;}
            }
        }

    }
    cout<<(ans==INT_MAX?-1:ans)<<endl;

}

#include <iostream>
#include <fstream>
#include <string>
#include <string.h>
#include <math.h>
#include <set>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

int n;
vector<int> a;
vector<int> b;

struct Node {
    vector<int> a;
    vector<int> b;
    int d;
};

int getBits(int x) {
    if (x == 0) return 0;
    for (int i = 1; ; i++) {
        if (x == 1) return i;
        x >>= 1;
    }
}

int solve(vector<int>& a, vector<int>&b, int d) {
    int n = a.size();
    bool strictIncrease = true;
    for (int i = 0; i < n; i++) {
        if (i >= 2) {
            if (i > 0 && b[i] > b[i - 1]) {
                strictIncrease = false;
            }
        }
    }
    if (strictIncrease) {
        return -1;
    }

    for (int i = 1; i < n; i++) {
        int x = a[i] ^ a[i - 1];
        if (i > 1 && a[i - 2] > x || i + 1 < n && x > a[i + 1]) {
            cout << 1 + d << endl;
            return 1;
        }
    }
    for (int i = 2; i < n; i++) {
        if (b[i] > 0 && b[i] == b[i - 1] && b[i] == b[i - 2]) {
            cout << 2 + d << endl;
            return 2 + d;
        }
    }
    return 0;
}

int find(vector<int>&a, vector<int>&b) {
    Node node = Node();
    node.a = a;
    node.b = b;
    node.d = 0;
    queue<Node> q;
    q.push(node);

    while (!q.empty()) {
        Node node = q.front();
        q.pop();

        vector<int>& a = node.a;
        vector<int>& b = node.b;
        int d = node.d;
        int n = a.size();

        for (int i = 0; i < n - 1; i++) {
            if (b[i] == b[i + 1]) {
                vector<int> a1;
                vector<int> b1;
                for (int j = 0; j < i; j++) {
                    a1.push_back(a[j]);
                    b1.push_back(b[j]);
                }
                int temp = a[i] ^ a[i + 1];
                a1.push_back(temp);
                b1.push_back(getBits(temp));
                for (int j = i + 2; j < n; j++) {
                    a1.push_back(a[j]);
                    b1.push_back(b[j]);
                }
                int re = solve(a1, b1, d + 1);
                if (re > 0) return re;
                Node node1;
                node1.a = a1;
                node1.b = b1;
                node1.d = d + 1;
                q.push(node1);
            }
        }
    }
    cout << -1 << endl;
    return -1;
}

void main() {
#ifndef ONLINE_JUDGE
    ifstream cin("xor.in");
#endif
    cin >> n;
    a.resize(n);
    b.resize(n);
    bool strictIncrease = true;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = getBits(a[i]);
        if (i >= 2) {
            if (i > 0 && b[i] > b[i - 1]) {
                strictIncrease = false;
            }
        }
    }
    if (strictIncrease) {
        cout << -1 << endl;
        return;
    }

    for (int i = 0; i < n; i++) {
        if (i > 0) {
            int x = a[i] ^ a[i - 1];
            if (i > 1 && a[i-2] > x || i+1<n && x>a[i+1]) {
                cout << 1 << endl;
                return;
            }
        }
    }
    for (int i = 2; i < n; i++) {
        if (b[i] > 0 && b[i] == b[i - 1] && b[i] == b[i - 2]) {
            cout << 2 << endl;
            return;
        }
    }

    int minsteps = -1;
    int steps = 0;
    for (int i = 1; i < n; i++) {
        int vr = 0;
        for (int j = i; j >= 1; j--) {
            vr ^= a[j];
            int vl = 0;
            for (int k = j - 1; k >= 0; k--) {
                vl ^= a[k];
                if (vl > vr) {
                    steps = i - j + j-1-k;
                    if (minsteps == -1 || steps < minsteps) minsteps = steps;
                    break;
                }
            }
        }
    }
    cout << minsteps << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1e5+10;
int a[maxn],pre,las;
int tr[maxn*32][2],root[maxn*33],tot=0;
void insert(int x,int k)
{
	int rt=0;
	for(int i=31;i>=0;i--){
		int id=0;
		if(x&(1<<i))	id=1;
		if(tr[rt][id]==0)	tr[rt][id]=++tot;
		rt=tr[rt][id];root[rt]=k;
	}
}
int check(int x,int y)
{
	int rt=0;
	for(int i=31;i>=0;i--){
		int d1=0,d2=0;
		if(x&(1<<i))	d1=1;
		if(y&(1<<i))	d2=1;
		if(d2){
			if(d1){
				if(tr[rt][0]==0)	return 1e9;
				rt=tr[rt][0];
			}
			else{
				if(tr[rt][1]==0)	return 1e9;
				rt=tr[rt][1];
			}
		}else{
			if(d1){
				if(tr[rt][0])		return root[tr[rt][0]];
				if(tr[rt][1]==0)	return 1e9;
				rt=tr[rt][1];
			}else{
				if(tr[rt][1])		return root[tr[rt][1]];
				if(tr[rt][0]==0)	return 1e9;
				rt=tr[rt][0];
			}
		}
	}
	return root[rt];
}
int check1(int x,int y)
{
	int rt=0;
	for(int i=31;i>=0;i--){
		int d1=0,d2=0;
		if(x&(1<<i))	d1=1;
		if(y&(1<<i))	d2=1;
		if(d2==0){
			if(d1){
				if(tr[rt][1]==0)	return 1e9;
				rt=tr[rt][1];
			}
			else{
				if(tr[rt][0]==0)	return 1e9;
				rt=tr[rt][0];
			}
		}else{
			if(d1==0){
				if(tr[rt][0])		return root[tr[rt][0]];
				if(tr[rt][1]==0)	return 1e9;
				rt=tr[rt][1];
			}else{
				if(tr[rt][1])		return root[tr[rt][1]];
				if(tr[rt][0]==0)	return 1e9;
				rt=tr[rt][0];
			}
		}
	}
	return root[rt];
}
signed main()
{
	int n;scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	int ans=1e9;
	insert(0,0);
	for(int i=1;i<n;i++){
		pre=pre^a[i];
		if(i!=1){
			int rec=check(pre,a[i+1]+1);
			//cout<<i<<" "<<rec<<endl;
//			if(abs(i-rec)==1){
//				printf("%lld+%lld\n",i,rec);
//				return 0;
//			}
			ans=min(ans,abs(i-rec));
		}
		insert(pre,i);
	}
	memset(tr,0,sizeof tr);memset(root,0,sizeof root);tot=0;
	insert(0,n+1);
	for(int i=n;i>1;i--){
		las=las^a[i];
		if(i!=n){
			int rec=check1(las,a[i-1]-1);//a[i-1]>a[i]
			//cout<<i<<" "<<rec<<endl;
//			if(abs(i-rec)==1){
//				printf("%lld-%lld\n",i,rec);
//				return 0;
//			}
			ans=min(ans,abs(i-rec));
		}
		insert(las,i);
	}
	ans--;
	if(ans>n){
		printf("-1\n");return 0;
	}
	cout<<ans<<endl;
}
/*
4
2 5 6 8
*/

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using db = double;
using str = string; // yay python!

using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

#define tcT template<class T
#define tcTU tcT, class U
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
tcT> using PR = pair<T,T>;

// pairs
#define mp make_pair
#define f first
#define s second

// vectors
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

// loops
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const int mxN = 2e5+5;
const ll INF = 1e18; // not too close to LLONG_MAX
const ld PI = acos((ld)-1);
const int tSZ = (1 << 21);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;

// helper funcs
constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down

int add(int f, int s){ f += s; if(f >= MOD) f %= MOD; if(f < 0) f += MOD;	return f; } // add f to s and make sure it's in range
int mul(long long f, int s){ f *= s; if(f >= MOD) f %= MOD; return f;} // multiply f and s and make sure it's in range
int pw(int x, int y) { int ans = 1, ml = x; while(y) { if(y & 1) ans = mul(ans, ml); ml = mul(ml, ml);	y >>= 1; } return ans; } // number x to a power y
int inv(int x) { return pw(x, MOD - 2); }

tcT> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; } // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; }

tcTU> T fstTrue(T lo, T hi, U f) {
	hi ++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo)/2;
		f(mid) ? hi = mid : lo = mid+1;
	}
	return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
	lo --; assert(lo <= hi); // assuming f is decreasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo+1)/2;
		f(mid) ? lo = mid : hi = mid-1;
	}
	return lo;
}
tcT> void remDup(vector<T>& v) { // sort and remove duplicates
	sort(all(v)); v.erase(unique(all(v)),end(v)); }
tcTU> void erase(T& t, const U& u) { // don't erase
	auto it = t.find(u); assert(it != end(t));
	t.erase(u); } // element that doesn't exist from (multi)set

 // INPUT
#define tcTUU tcT, class ...U
tcT> void re(complex<T>& c);
tcTU> void re(pair<T,U>& p);
tcT> void re(vector<T>& v);
tcT, size_t SZ> void re(AR<T,SZ>& a);

tcT> void re(T& x) { cin >> x; }
void re(db& d) { str t; re(t); d = stod(t); }
void re(ld& d) { str t; re(t); d = stold(t); }
tcTUU> void re(T& t, U&... u) { re(t); re(u...); }

tcT> void re(complex<T>& c) { T a,b; re(a,b); c = {a,b}; }
tcTU> void re(pair<T,U>& p) { re(p.f,p.s); }
tcT> void re(vector<T>& x) { trav(a,x) re(a); }
tcT, size_t SZ> void re(AR<T,SZ>& x) { trav(a,x) re(a); }
tcT> void rv(int& n, vector<T>& x) { re(n); x.rsz(n); trav(a,x) re(a); }

// TO_STRING
#define ts to_string
str ts(char c) { return str(1,c); }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
str ts(bool b) {
	#ifdef LOCAL
		return b ? "true" : "false";
	#else
		return ts((int)b);
	#endif
}
tcT> str ts(complex<T> c) {
	stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) {
	str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
	str res = ""; F0R(i,SZ) res += char('0'+b[i]);
	return res; }
tcTU> str ts(pair<T,U> p);
tcT> str ts(T v) { // containers with begin(), end()
	#ifdef LOCAL
		bool fst = 1; str res = "{";
		for (const auto& x: v) {
			if (!fst) res += ", ";
			fst = 0; res += ts(x);
		}
		res += "}"; return res;
	#else
		bool fst = 1; str res = "";
		for (const auto& x: v) {
			if (!fst) res += " ";
			fst = 0; res += ts(x);
		}
		return res;

	#endif
}
tcTU> str ts(pair<T,U> p) {
	#ifdef LOCAL
		return "("+ts(p.f)+", "+ts(p.s)+")";
	#else
		return ts(p.f)+" "+ts(p.s);
	#endif
}

// OUTPUT
tcT> void pr(T x) { cout << ts(x); }
tcTUU> void pr(const T& t, const U&... u) {
	pr(t); pr(u...); }
void ps() { pr("\n"); } // print w/ spaces
tcTUU> void ps(const T& t, const U&... u) {
	pr(t); if (sizeof...(u)) pr(" "); ps(u...); }

 // DEBUG
void DBG() { cerr << "]" << endl; }
tcTUU> void DBG(const T& t, const U&... u) {
	cerr << ts(t); if (sizeof...(u)) cerr << ", ";
	DBG(u...); }
#ifdef LOCAL // compile with -DLOCAL, chk -> fake assert
	#define dbg(...) cerr << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
	#define chk(...) if (!(__VA_ARGS__)) cerr << "Line(" << __LINE__ << ") -> function(" \
		 << __FUNCTION__  << ") -> CHK FAILED: (" << #__VA_ARGS__ << ")" << "\n", exit(0);
#else
	#define dbg(...) 0
	#define chk(...) 0
#endif

// FILE I/O
void setIn(str s) { freopen(s.c_str(),"r",stdin); }
void setOut(str s) { freopen(s.c_str(),"w",stdout); }
void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }
void setIO(str s = "") {
	unsyncIO();
	// cin.exceptions(cin.failbit);
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

int n, a[mxN];
int t[mxN];

int rec(int k, int cnt)
{
	if(k == n)
	{
	/*	for(int i = 0; i < cnt; i++)
		{
			pr(t[i], " ");
		}
		ps();*/

		for(int i = 0; i < cnt; i++)
		{
			if(i - 1 >= 0 && t[i] < t[i - 1]) return n - cnt;
			if(i + 1 < cnt && t[i] > t[i + 1]) return n - cnt;
		}
		return n + 1;
	}
	int ans = n + 1;
	int tmp = 0;
	for(int j = k; j < n; j++)
	{
		tmp ^= a[j];
		t[cnt] = tmp;
		ans = min(ans, rec(j + 1, cnt + 1));
	}
	return ans;
}

int solve()
{
	ll tmp = 0;
	int ans = n + 1;
	for(int i = 1; i < n - 1; i++)
	{
		if(i && ((a[i] ^ a[i + 1]) < a[i - 1]))
		{
			return 1;
		}
		if((a[i] ^a[i - 1]) > a[i + 1])
		{
			return 1;
		}
	}
	if(n <= 28)
	{
		int t = rec(0, 0);
		if(t == n + 1) t = -1;
	return t;
	}
	else return -1;
	//return t;
}
int main()
{
	setIO();

	re(n);

	for(int i = 0; i < n; i++)
	{
		re(a[i]);
	}

	ps(solve());

	return 0;
	// you should actually read the stuff at the bottom
}

 /* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/

//#pragma GCC target ("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//#include <ext/rope>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_cxx;
//using namespace __gnu_pbds;

#define files(fin, fout) freopen(fin, "r", stdin); freopen(fout, "w", stdout)
#define foru(i, n) for(int i = 0; i < n; ++i)
#define fori(i, j, n) for(int i = j; i < n; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define mpm(a, b) make_pair(min(a, b), max(a, b))
#define mpint(a, b) ((ll)(a) * (INT_MAX) + (b))
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define mbort(a) sort(all(a))
#define cinm(a) for(auto &i : a) cin >> i
#define sz(a) (int)(a).size()
#define coutm(a) for(auto &i : a) cout << i << ' '; cout << '\n'
#define debug(x) cout << #x << ": " << x << '\n'
#define debugm(x) cout << #x << ":\n"; coutm(x)
#define ff first
#define ss second

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const signed inf = 1000000100;
const ll inf64 = 1ll * inf * inf;
const ll mod = 1e9 + 7;

mt19937 rng(0);

#define int long long

//typedef tree<string, null_type, less_equal<string>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

bool get_bit(int x, int i){
    return x & (1ll << i);
}

const int N = 2e5 + 10;

struct Node{
    int mx;
    int mn;
    Node(){
        mx = -inf64;
        mn = inf64;
    }
};

vector <Node> t(4 * N);
int tx = 0;

void update(int i, int x, int v = 0, int tl = 0, int tr = N - 1){
    if(i < tl || i > tr || tl > tr)
        return;
    if(tl == tr){
        t[v].mx = x;
        t[v].mn = x;
        return;
    }
    int tm = (tl + tr) / 2;
    if(i <= tm)
        update(i, x, 2 * v + 1, tl, tm);
    else
        update(i, x, 2 * v + 2, tm + 1, tr);
    t[v].mx = max(t[2 * v + 1].mx, t[2 * v + 2].mx);
    t[v].mn = min(t[2 * v + 1].mn, t[2 * v + 2].mn);
}

pii getr(int x, int v = 0, int tl = 0, int tr = N - 1){
    if(tl > tr)
        return mp(-inf64, -1);
    if(tl == tr){
        return mp(t[v].mx ^ tx, tr);
    }
    int tm = (tl + tr) / 2;
    int rmx = t[2 * v + 2].mx ^ tx;
    int lmx = t[2 * v + 1].mx ^ tx;
    if(rmx > x){
        return getr(x, 2 * v + 2, tm + 1, tr);
    }
    else{
        return getr(x, 2 * v + 1, tl, tm);
    }
}

pii getl(int x, int v = 0, int tl = 0, int tr = N - 1){
    if(tl > tr)
        return mp(inf64, -1);
    if(tl == tr){
        return mp(t[v].mn ^ tx, tr);
    }
    int tm = (tl + tr) / 2;
    int rmx = t[2 * v + 2].mn ^ tx;
    int lmx = t[2 * v + 1].mn ^ tx;
    if(lmx < x){
        return getl(x, 2 * v + 1, tl, tm);
    }
    else{
        return getl(x, 2 * v + 2, tm + 1, tr);
    }
}

void run() {
    int n;
    cin >> n;
    vector <int> a(n);
    cinm(a);
    vector <int> psufxor(n);
    int ans = inf64;
    for(int i = 0; i < n; ++i){
        pii rb = getr(a[i]);
        if(rb.ff > a[i]){
            ans = min(ans, i - rb.ss - 1);
        }
        tx ^= a[i];
        update(i, a[i] ^ tx);
    }
    tx = 0;
    t.assign(4 * N, Node());
    for(int i = n - 1; i >= 0; --i){
        pii lb = getl(a[i]);
        if(lb.ff < a[i]){
            ans = min(ans, lb.ss - i - 1);
        }
        tx ^= a[i];
        update(i, a[i] ^ tx);
    }
    if(ans > inf){
        cout << -1;
        return;
    }
    cout << ans;
}

signed main(){
    //files("input.txt", "output.txt");
    //files("spiral.in", "spiral.out");
    iostream::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--){
        run();
        cout.flush();
    }
}

#include <bits/stdc++.h>

#define input   std::cin
#define output  std::cout

#define llg     long long

#define MAXN    100005

int N;
int hbit[MAXN], cnt[35];
std::vector <int> a;

int32_t main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    input >> N;
    a.resize(N);
    for (auto &it:a) input >> it;

    bool chance = false;
    for (int i=0; i<N; ++i) {
        hbit[i] = 0;
        for (int j=0; j<31; ++j) {
            if ((1<<j)&a[i])
                hbit[i] = j;
        }
        if (i > 0 && hbit[i-1] == hbit[i]) chance = true;
        cnt[hbit[i]] ++;
    }

    if (!chance) {
        output << -1;
    }
    else {
        int ans = -1;
        for (int i=0; i<35; ++i) {
            if (cnt[i] >= 3) ans = 1;
        }

        if (ans == -1) {
            for (int l=0; l<N; ++l) {
                for (int r=l+1; r<N; ++r) {
                    for (int m=l; m<r; ++m) {
                        int x1 = 0;
                        int x2 = 0;
                        for (int k=l; k<=m; ++k)
                            x1 ^= a[k];
                        for (int k=m+1; k<=r; ++k)
                            x2 ^= a[k];
                        if (x1 > x2) {
                            if (ans == -1) ans = r-l-1;
                            else ans = std::min(ans, r-l+1);
                        }
                    }
                }
            }
        }

        output << ans << '\n';
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 998244353
#define N 100005
int n;
int a[N];
int pref[N],suff[N];
string s[N],s2[N];
bool Check(int n,int pos){
    return (bool)(n & (1<<pos));
}
int node_cnt=1;

int trie[3000005][2];
int nodemx[3000005];

int node_cnt2=1;

int trie2[3000005][2];
int nodemn[3000005];

void Add(string s,int id)
{
    int n=s.size();
    int cur=1;
    for(int i=0;i<n;i++)
    {
        int ch=s[i]-'0';
        if(!trie[cur][ch]) trie[cur][ch]=++node_cnt;
        cur=trie[cur][ch];
        nodemx[cur]=max(nodemx[cur],id);
    }
}
int Search(string s,int mid){
    int n=s.size();
    int ret=0;
    int cur=1;
    for(int i=0,j=30;i<n;i++,j--){
        int ch=s[i]-'0';
        if(trie[cur][!ch] && nodemx[trie[cur][!ch]]>=mid){
            cur=trie[cur][!ch];
            ret+=(1<<j);
        }
        else{
            cur=trie[cur][ch];
        }
    }
    return ret;
}
void Add2(string s,int id)
{
    int n=s.size();
    int cur=1;
    for(int i=0;i<n;i++)
    {
        int ch=s[i]-'0';
        if(!trie2[cur][ch]) trie2[cur][ch]=++node_cnt2;
        cur=trie2[cur][ch];
        nodemn[cur]=min(nodemn[cur],id);
    }
}
int Search2(string s,int mid){
    int n=s.size();
    int ret=0;
    int cur=1;
    for(int i=0,j=30;i<n;i++,j--){
        int ch=s[i]-'0';
        if(trie2[cur][ch] && nodemn[trie2[cur][ch]]<=mid){
            cur=trie2[cur][ch];
        }
        else{
            cur=trie2[cur][!ch];
            ret+=(1<<j);
        }
    }
    return ret;
}
int main()
{
    fastio;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) pref[i]=(pref[i-1]^a[i]);
    for(int i=0;i<=n;i++){
        for(int j=30;j>=0;j--){
            if(Check(pref[i],j)) s[i]+='1';
            else s[i]+='0';
        }
    }
    int mn=INT_MAX;
    Add(s[0],0);
    for(int i=1;i<n;i++){
        if(Search(s[i],0)<=a[i+1]){
            Add(s[i],i);
            continue;
        }
        int lo=0,hi=i-1;
        while(lo<hi){
            int mid=(lo+hi+1)/2;
            if(Search(s[i],mid)>a[i+1]) lo=mid;
            else hi=mid-1;
        }
        mn=min(mn,i-lo-1);
        Add(s[i],i);
    }
    for(int i=n;i>=1;i--){
        suff[i]=(suff[i+1]^a[i]);
    }
    for(int i=1;i<=n+1;i++){
        for(int j=30;j>=0;j--){
            if(Check(suff[i],j)) s2[i]+='1';
            else s2[i]+='0';
        }
    }
    for(int i=1;i<=3000000;i++) nodemn[i]=n+2;
    Add2(s[n+1],n+1);
    for(int i=n;i>1;i--){
        if(Search2(s2[i],n+1)>=a[i-1]){
            Add2(s2[i],i);
            continue;
        }
        int lo=i+1,hi=n+1;
        while(lo<hi){
            int mid=(lo+hi)/2;
            if(Search2(s2[i],mid)<a[i-1]) hi=mid;
            else lo=mid+1;
        }
        mn=min(mn,hi-i-1);
        Add2(s2[i],i);
    }
    if(mn!=INT_MAX) cout<<mn<<endl;
    else cout<<-1<<endl;

}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>

using namespace std;

inline int read () {
	int ret = 0, t = 1;
	char c = getchar();
	while ((c < '0' || c > '9') && c != '-') c = getchar();
	if (c == '-') t = -1, c = getchar();
	while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
	return ret * t;
}
int n, a[100100], s[100100];
int highbit (int x) { if (x == 0) return -1; return log2(x); }

int main () {
	n = read();
	int i, j;
	for (i = 1; i <= n; i++) a[i] = read();
	for (i = 1; i < n; i++) {
		if (a[i] == a[i + 1]) { puts("1"); return 0; }
	}
	for (i = 1; i < n - 1; i++) if (highbit(a[i]) == highbit(a[i + 1]) && highbit(a[i + 1]) == highbit(a[i + 2])) {
		puts("1"); return 0;
	}
	for (i = 1; i <= n; i++) s[i] = s[i - 1] ^ a[i];
	int ans = 998244353;
	for (i = 2; i <= n; i++) {
		if (highbit(a[i]) != highbit(a[i - 1])) continue;
		for (j = i - 2; j >= 1; j--) {
			if (highbit(a[j]) == highbit(a[j - 1])) { ans = min(ans, i - j); break; }
			else if (a[j - 1] > (s[i] ^ s[j - 1])) { ans = min(ans, i - j); break; }
		}
		for (j = i - 2; j >= 0; j--){
			if (highbit(a[j]) == highbit(a[j + 1])) break;
			else if (a[i] < (s[i - 1] ^ s[j - 1])) { ans = min(ans, i - 1 - j); break; }
		}
	}
	if (ans == 998244353) puts("-1");
	else printf("%d\n", ans);
	return 0;
}

#include <string.h>
#include <assert.h>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <time.h>

#include <sstream>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <set>

#include <map>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cassert>
//#include<bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define clr(x) memset(x,0,sizeof(x))
#define _clr(x) memset(x,-1,sizeof(x))
#define fr(i,a,b) for(int i = a; i < b; ++i)
#define frr(i,a,b) for(int i = a; i > b; --i)
#define pb push_back
#define sf scanf

#define pf printf
#define mp make_pair
#define pir pair<int,int>
#define N 811100

using namespace std;
const ll mod = 998244353;

int n;
int a[N],c[N];
int max_v[N];
int lt[N],rt[N];
int l[N],r[N];
int id;

int max_q = 29;

int main(){
	cin>>n;
	fr(i,1,n+1){
		cin>>a[i];
	}

	for(int i = 3; i <=n; ++i){
		int s = 0;
		for(int j = 0; j<2;++j){
			s ^=a[i-j];
		}
		if(s < a[i-2]){
			cout<<1<<endl;
			return 0;
		}
	}

	int ans = n+1;
	for(int i = 2; i <=n; ++i){
		if(i+1<=n && i-2>=1){
			int s = 0;
			int ss = 0;
			for(int j = 0; j < 2; ++j){
				ss ^=a[i+j];
				s^=a[i-j-1];
			}
			if(s>ss){
				ans = 2;
			}
		}
	}

	for(int i = 1; i <=n; ++i){
		int s = 0;
		for(int j = i; j; --j){
			s ^=a[j];
			if((i<n&&s >a[i+1]) || (j>1&&s < a[j-1])){
				ans = min(ans, i-j);
			}
		}
	}
	if(ans==n+1)ans = -1;
	cout<<ans<<endl;
}

#include <bits/stdc++.h>
#define inf (int)(1e8)
using namespace std;

int n;
vector<int> a;

int cntd(int x);
int solve();
int calc(int i);

int main() {
  cin >> n;
  a.resize(n);
  for (auto &p : a) cin >> p;
  cout << solve() << endl;
  return 0;
}

int cntd(int x) {
  int res = 0;
  while (x) x >>= 1, ++res;
  return res;
}

int solve() {
  if (n == 2) return -1;
  int res = inf;
  res = min(res, calc(0));
  res = min(res, calc(n - 1));
  for (int i = 1; i < n; ++i)
    if (cntd(a[i]) != cntd(a[i - 1])) {
      res = min(res, calc(i));
      res = min(res, calc(i - 1));
    }
  if (n <= 100) {
    vector<int> sum(n + 1, 0);
    for (int i = 0; i < n; ++i) sum[i + 1] = sum[i] ^ a[i];
    for (int i = 0; i <= n; ++i)
      for (int j = i + 1; j <= n; ++j)
        for (int k = j + 1; k <= n; ++k)
          if (sum[i] ^ sum[j] > sum[j] ^ sum[k]) res = min(res, k - i - 2);
  }
  if (res == inf) return -1;
  return res;
}

int calc(int i) {
  int res = inf;
  if (i > 0) {
    int x = a[i], cnt = 0, id = i;
    while (++id < n) {
      x ^= a[id];
      ++cnt;
      if (a[i - 1] > x) {
        res = min(res, cnt);
        break;
      }
    }
  }
  if (i < n - 1) {
    int x = a[i], cnt = 0, id = i;
    while (--id >= 0) {
      x ^= a[id];
      ++cnt;
      if (x > a[i + 1]) {
        res = min(res, cnt);
        break;
      }
    }
  }
  if (i < n - 1) {
    int x = a[i + 1], cnt = 0, id = i + 1;
    while (++id < n) {
      x ^= a[id];
      ++cnt;
      if (a[i] > x) {
        res = min(res, cnt);
        break;
      }
    }
  }
  return res;
}

#include <bits/stdc++.h>
#define IRC "The weakest garbage"
#define sc static const
#define st static
#define ai = {}
#define fst first.first
#define fnd first.second
#define sst second.first
#define snd second.second
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back(a)
#define r(a, b) for (int a=1; a<=(b); ++a)
#define re(a, b, c) for (int a=(b); a<=(c); ++a)
#define rr(a, b) for (int a=(b); a>=1; --a)
#define rre(a, b, c) for (int a=(c); a>=(b); --a)
#define rv(a, b) for (unsigned int i=0; i<(b).size() && (a = (b)[i], true); ++i)
#define sq(a) ((a)*(a))
#define lb(a) ((a)&(-(a)))
using namespace std;

sc int maxn = 100005, maxlog = 31;

int n, dt_a[maxn];
int tr_ch[maxn * maxlog][2]ai, tr_mxv[maxn * maxlog]ai, tr_v[maxn * maxlog]ai, tr_lazy[maxn * maxlog]ai, tr_new = 1;

inline void pushdown(int x, int bit) {
	if (tr_lazy[x]) {
		if (tr_lazy[x]&(1<<bit)) swap(tr_ch[x][0], tr_ch[x][1]);
		re (i, 0, 1) if (tr_ch[x][i]) tr_lazy[tr_ch[x][i]] ^= tr_lazy[x];
		tr_lazy[x] = 0;
	}
}

inline void join(int x, int v) {
	int p = 1;
	for (int i = maxlog - 1; i >= 0; --i) {
		pushdown(p, i);
		int c = x&(1<<i);
		tr_mxv[p] = max(tr_mxv[p], v);
		if (!tr_ch[p][c]) tr_ch[p][c] = ++tr_new;
		p = tr_ch[p][c];
	}
	tr_v[p] = max(tr_v[p], v);
	tr_mxv[p] = max(tr_mxv[p], v);
}

inline void xorbound(int x) {
	tr_lazy[1] ^= x;
}

inline int querygreater(int x) {
	int p = 1, ret = 0;
	for (int i = maxlog - 1; i >= 0 && p; --i) {
		pushdown(p, i);
		int c = x&(1<<i);
		if (!c) {
			ret = max(ret, tr_mxv[tr_ch[p][1]]);
			p = tr_ch[p][0];
		} else p = tr_ch[p][1];
	}
	return ret;
}

inline int queryless(int x) {
	int p = 1, ret = 0;
	for (int i = maxlog - 1; i >= 0 && p; --i) {
		pushdown(p, i);
		int c = x&(1<<i);
		if (c) {
			ret = max(ret, tr_mxv[tr_ch[p][0]]);
			p = tr_ch[p][1];
		} else p = tr_ch[p][0];
	}
	return ret;
}

int main() {
	cin >> n; r (i, n) cin >> dt_a[i];
	int ans = 0x3f3f3f3f;
	r (i, n) {
		int q = querygreater(dt_a[i]);
		if (q != 0) ans = min(ans, i - q - 1);
		join(0, i), xorbound(dt_a[i]);
	}
	memset(tr_ch, 0, sizeof(tr_ch));
	memset(tr_mxv, 0, sizeof(tr_mxv));
	memset(tr_v, 0, sizeof(tr_v));
	memset(tr_lazy, 0, sizeof(tr_lazy));
	tr_new = 1;
	rr (i, n) {
		int q = queryless(dt_a[i]);
		if (q != 0) ans = min(ans, (n - i + 1) - q - 1);
		join(0, n - i + 1), xorbound(dt_a[i]);
	}
	if (ans == 0x3f3f3f3f) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}

/*
5
1 9 10 13 14
*/

//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <vector>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <bitset>
#include <cassert>
using namespace std;

#define MOD 998244353

struct Node {
	vector<int> adj;
};

inline uint64_t modpow(uint64_t base, uint64_t exp, uint64_t modulus) {
	base %= modulus;
	uint64_t result = 1;
	while (exp > 0) {
		if (exp & 1) result = (result * base) % modulus;
		base = (base * base) % modulus;
		exp >>= 1;
	}
	return result;
}

inline uint64_t modinv(uint64_t x, uint64_t mod) {
	return modpow(x, mod - 2, mod);
}

uint64_t mypow(uint64_t base, uint64_t exp) {
	uint64_t result = 1;
	while (exp > 0) {
		if (exp & 1) result = (result * base);
		base = (base * base);
		exp >>= 1;
	}
	return result;
}

const unsigned int b[] = { 0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000 };
const unsigned int S[] = { 1, 2, 4, 8, 16 };

unsigned int hbs(int v) {
	unsigned int r = 0; // result of log2(v) will go here

	for (int i = 4; i >= 0; i--) // unroll for speed...
	{
		if (v & b[i])
		{
			v >>= S[i];
			r |= S[i];
		}
	}
	return r;
}

int main() {
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int64_t n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = hbs(a[i]);
	}
	bool done = false;
	for (int i = 2; i < n; i++) {
		if (a[i - 1] == a[i]) {
			done = true;
		}
	}
	if (done || n > 2*(b.back()+1)) {
		cout << 1 << endl;
	}
	vector<int> xors(n + 1);
	xors[0] = 0;
	for (int i = 0; i < n; i++) {
		xors[i + 1] = xors[i]^ a[i];
	}
	int res = 1000000;
	for (int i = 0; i < xors.size()-1; i++) {
		for (int j = i + 1; j < xors.size()-1; j++) {
			if ((xors[i] ^ xors[j]) > a[j]) {
				res = min(j - i-1, res);
			}
		}
	}
	for (int i = n; i >= 1; i--) {
		for (int j = i - 1; j >= 1; j--) {
			if ((xors[i] ^ xors[j]) < a[j-1]) {
				res = min(i - j - 1, res);
			}
		}
	}
	if (res == 1000000) res = -1;
	cout << res << endl;

	return 0;
}

/*
5
2 4 8 16 17
*/

#include <bits/stdc++.h>
using namespace std;
const long long MOD=1000000007;
// const long long MOD=998244353;
#define LOCAL
#pragma region Macros
typedef long long ll;
typedef __int128_t i128;
typedef unsigned int uint;
typedef unsigned long long ull;
#define ALL(x) (x).begin(),(x).end()
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U,typename V>
ostream&operator<<(ostream &os,const tuple<T,U,V> &t){
    os << '(' << get<0>(t) << ',' << get<1>(t) << ',' << get<2>(t) << ')';
    return os;
}
template<typename T,typename U,typename V,typename W>
ostream&operator<<(ostream &os,const tuple<T,U,V,W> &t){
    os << '(' << get<0>(t) << ',' << get<1>(t) << ',' << get<2>(t) << ',' << get<3>(t) << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
    }
    os << '}';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const unordered_map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();){
        os << *itr;
        if (++itr!=s.end()) os << ',';
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const multiset<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();){
        os << *itr;
        if (++itr!=s.end()) os << ',';
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const unordered_set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();){
        os << *itr;
        if (++itr!=s.end()) os << ',';
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const deque<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

const int MAX_B=30;

int msb(int x){
    for (int i=MAX_B-1;i>=0;--i){
        if (x&1<<i){
            return i;
        }
    }
    return 0;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n); cin >> a;

    vector<int> cnt(MAX_B,0);
    for (int i=0;i<n;++i) ++cnt[msb(a[i])];
    for (int i=0;i<MAX_B;++i){
        if (cnt[i]>2){
            cout << 1 << '\n';
            return 0;
        }
    }

    auto inc=[](vector<int> v){
        for (int i=0;i+1<v.size();++i){
            if (v[i+1]<v[i]) return true;
        }
        return false;
    };
    auto check1=[&](int l,int r){
        vector<int> b;
        for (int i=0;i<l;++i) b.emplace_back(a[i]);
        int XOR=0;
        for (int i=l;i<r;++i) XOR^=a[i];
        b.emplace_back(XOR);
        for (int i=r;i<n;++i) b.emplace_back(a[i]);
        return (inc(b)?r-l-1:INF);
    };

    auto check2=[&](int l1,int r1,int l2,int r2){
        vector<int> b;
        for (int i=0;i<l1;++i) b.emplace_back(a[i]);
        int XOR1=0;
        for (int i=l1;i<r1;++i) XOR1^=a[i];
        b.emplace_back(XOR1);
        for (int i=r1;i<l2;++i) b.emplace_back(a[i]);
        int XOR2=0;
        for (int i=l2;i<r2;++i) XOR2^=a[i];
        b.emplace_back(XOR2);
        for (int i=r2;i<n;++i) b.emplace_back(a[i]);
        return (inc(b)?r1-l1-1+r2-l2-1:INF);
    };

    int ans=INF;
    for (int i=0;i<n;++i){
        for (int j=i+2;j<n;++j){
            chmin(ans,check1(i,j));
        }
    }

    for (int i=0;i<n;++i){
        for (int j=i+2;j<n;++j){
            for (int k=j;k<n;++k){
                for (int l=k+2;l<n;++l){
                    chmin(ans,check2(i,j,k,l));
                }
            }
        }
    }

    cout << (ans==INF?-1:ans) << '\n';
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
ll po[50];
ll a[100005];

ll n;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    ll mn = n;
    ll mx = 0;
    for (int i = 1; i <= n; i++)
    {
        ll a1;
        ll sum = 0;
        cin >> a[i];
        a1 = a[i];
        ll x = log2(a1);
        po[x]++;
        mx = max(mx, po[x]);
    }
    if (mx >= 3)
        cout << 1;
    else
    {
        for (int i = 1; i <= n; i++)
        {
            ll sum = a[i];
            ll cnt1 = 0;
            for (int j = i + 1; j <= n; j++)
            {
                cnt1++;
                sum =sum^a[j];
                if (sum < a[i - 1] and i > 1 || sum > a[j + 1] and j < n)
                {
                    mn = min(mn, cnt1);
                }
            }
        }
        if (mn==n)
            mn = -1;
        cout << mn << endl;
    }
}

#include <bits/stdc++.h>

#define TASK ""
#define faster ios_base::sync_with_stdio(false) , cin.tie(NULL)
#define FOR(i , a , b) for(int i = a ; i <= b ; ++i)
#define FORD(i , a , b) for(int i = a ; i >= b ; --i)

using namespace std;

const int N = 1e5 + 5;

int t , n , p , k , a[N] , b[N];

bool check(int x){
    if(b[x + 1] > a[x + 2]) return true;
    if(a[n - x - 1] > (b[n] ^ b[n - x - 1])) return true;
    FOR(i , x + 2 , n - 1){
        int t = b[i] ^ b[i - x - 1];
        if(t < a[i - x - 1] || t > a[i + 1]) return true;
    }
    return false;
}

int main(){
//    freopen (TASK".inp" , "r" , stdin);
//    freopen (TASK".out" , "w" , stdout);
    faster;
    cin >> n;
    if(n <= 2){
        cout << -1;
        return 0;
    }
    b[0] = 0;
    FOR(i , 1 , n) {cin >> a[i]; b[i] = b[i - 1] ^ a[i];}
    int l = 1 , r = n - 2 , res = -1;
    FOR(mid , l , r)
        if(check(mid)){
            res = mid;
            break;
        }
    cout << res;
    return 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
using namespace std;
const int N=200010;
typedef long long LL;
LL sz[N];
string str;
int main(void)
{
    int t;
    cin>>t;
    while(t--)
    {
        //dp[i]=dp[i-k] (i-p)*y dp[i-k]+x
        int n,p,k;
        cin>>n>>p>>k;
        cin>>str;
        str=" "+str;
        memset(sz,0x3f,sizeof sz);
        int x,y;
        cin>>x>>y;
        for(int i=1;i<=k;i++)str+='1';
        for(int i=0;i<p;i++)sz[i]=0;//
        for(int i=p;i<=n+k;i++)
        {
            if(str[i]=='1')
            {
                if(i<=n)sz[i]=(i-p)*y;
                if(i>=p+k)sz[i]=min(sz[i],sz[i-k]);
            }
            else
            {
                if(i<=n)sz[i]=(i-p)*y+x;
                if(i>=p+k)sz[i]=min(sz[i],sz[i-k]+x);
            }
            //cout<<sz[i]<<" ";
        }
        LL res=1e18;
        for(int i=n+1;i<=n+k;i++)
        {
            res=min(res,sz[i]);
        }
        cout<<res<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define pb push_back
#define db double
#define int ll
using namespace std;
const int maxn = 200001, inf = 2147483647;
const ll mod = 1 ? 998244353 : 1000000007, linf = 9223372036854775807;
const double pi = acos(-1);
inline ll mi(ll a, ll b, ll mm = mod) { a %= mm; ll u = 1; while (b) { if (b & 1)u = u * a % mm; a = a * a % mm, b >>= 1; }return u; }
inline ll gcd(ll a, ll b) { ll c = a % b; while (c)a = b, b = c, c = a % b; return b; }
inline void mem(int* a, int p = 0, int len = maxn) { for (int i = 0; i < len; i++)a[i] = p; }
struct p {}e[maxn];
static bool cmp(int i, int j) { return i > j; };
int t, n, m, a[maxn], b[maxn], x, su, y, xx;
signed main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);//sf和cin混用会出错
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	a[0] = -1, a[n + 1] = inf;
	for (int mm = 1; mm < 40; mm++)
		for (int i = 1; i < n - mm+1; i++)
		{
			int u = 0;
			for (int j = i, jj = 0; jj <= mm ; jj++, j++)
				u ^= a[j];
			if (u<a[i - 1] || u>a[i + mm + 1])
			{
				cout << mm;
				return 0;
			}
			for (int jj = i; jj <i+mm; jj++)
			{
				int ua = 0, ub = 0;
				for (int ii = i; ii <= jj; ii++)
					ua ^= a[ii];
				for (int jjj = jj + 1; jjj <= i+mm; jjj++)
					ub ^= a[jjj];
				if (ua > ub)
				{
					cout << mm;
					return 0;
				}
			}
		}
	cout << -1;
}

#include <bits/stdc++.h>

#define ll long long
#define ld double
#define pi acos(-1)
#define pb push_back
#define mst(a, i) memset(a, i, sizeof(a))
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp(x,y) make_pair(x,y)
#define rep(i,a,n)  for(ll i=a;i<=n;i++)
#define per(i,n,a)  for(ll i=n;i>=a;i--)
#define dbg(x) cout << #x << "===" << x << endl
#define dbgg(l,r,x) for(ll i=l;i<=r;i++) cout<<x[i]<<" ";cout<<"<<<"<<#x;cout<<endl
using namespace std;

template<class T>void read(T &x){T res=0,f=1;char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}while(isdigit(c)){res=(res<<3)+(res<<1)+c-'0';c=getchar();}x=res*f;}
inline void print(ll x){if(x<0){putchar('-');x=-x;}if(x>9)print(x/10);putchar(x%10+'0');}
const ll maxn = 1e5 + 10;
const ll mod = 1e9+7;

ll n,a[maxn];
//ll inv(ll a){return a==1?1:(ll)(mod-mod/a)*inv(mod%a)%mod;}
//ll gcd(ll a,ll b){return (b==0)?a:gcd(b,a%b);}
//ll qpow(ll a,ll p,ll mod){if(p<=0) return 1;ll ans=1;a=a%mod;while(p){if(p&1)ans=(ans*a)%mod;p>>=1;a=(a*a)%mod;}return ans;}
//void build(ll p,ll l,ll r){if(l==r){sum[p]=a[l];return ;}ll mid=(l+r)>>1;build(p<<1,l,mid);build(p<<1|1,mid+1,r);sum[p]=sum[p<<1]+sum[p<<1|1];}
//void pushdown(ll p,ll l,ll r){ll mid=(l+r)>>1;sum[p<<1]+=(mid-l+1)*tag[p];sum[p<<1|1]+=(r-(mid+1)+1)*tag[p];tag[p<<1]+=tag[p];tag[p<<1|1]+=tag[p];tag[p]=0;}
//void update(ll p,ll l,ll r,ll x,ll y,ll k){if(x<=l&&r<=y){sum[p]+=(r-l+1)*k;tag[p]+=k;return ;}pushdown(p,l,r);ll mid=(l+r)>>1;if(x<=mid) update(p<<1,l,mid,x,y,k);if(y>mid) update(p<<1|1,mid+1,r,x,y,k);sum[p]=sum[p<<1]+sum[p<<1|1];}
//ll query(ll p,ll l,ll r,ll x,ll y){ll res=0;if(x<=l&&r<=y) return sum[p];ll mid=(l+r)>>1;pushdown(p,l,r);if(x<=mid) res+=query(p<<1,l,mid,x,y);if(y>mid) res+=query(p<<1|1,mid+1,r,x,y);return res;}
int main() {
    ll _s = 1;
    //read(_s);
    //freopen("testdata.in","r",stdin);
	//freopen("testout.out","w",stdout);
    for (ll _=1;_<=_s;_++) {
        read(n);
        mst(a,0);
        rep(i,1,n)read(a[i]);
        ll ans=-1;
        ll b,c;
        rep(i,1,n){
            b=a[i]^a[i+1];
            c=b^a[i+2];
            if(i-1>=1){
                if(b<a[i-1]){
                    ans=1;break;
                }
                if(c<a[i-1]){
                    ans=2;break;
                }
            }
            if(i+2<=n&&b>a[i+2]){
                ans=1;break;
            }
            if(i+3<=n&&b>a[i+3]){
                ans=2;break;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
/*
input:::

output:::

*/

#include <cassert>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <chrono>
#include <algorithm>
#include <numeric>
#include <atomic>
#include <tuple>
#include <fstream>
#include <random>
#include <future>
#include <iterator>
#include <functional>
#include <thread>
#include <bitset>
#include <cstddef>
#include <utility>
#include <type_traits>
#include <complex>
#include <array>
#include <map>
#include <set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

template <typename T>
using vec = vector<T>;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
auto _fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return cout.tie(nullptr); }();

template <typename T>
istream& operator>>(istream& in, vector<T>& v) {
    for (size_t i = 0; i < v.size(); ++i) {
        in >> v[i];
    }
    return in;
}

template <typename T>
ostream& operator<<(ostream& out, vector<T>& v) {
    if (!v.empty()) {
        out << v.front();
        for (size_t i = 1; i < v.size(); ++i) {
            out << " " << v[i];
        }
    }
    return out;
}

template <typename T, size_t Size>
istream& operator>>(istream& in, array<T, Size>& v) {
    for (size_t i = 0; i < Size; ++i) {
        in >> v[i];
    }
    return in;
}

template <typename T, size_t Size>
ostream& operator<<(ostream& out, array<T, Size>& v) {
    if (!v.empty()) {
        out << v.front();
        for (size_t i = 1; i < v.size(); ++i) {
            out << " " << v[i];
        }
    }
    return out;
}

inline int64_t gcd(int64_t a, int64_t b)
{
    if (a < b) std::swap(a, b);
    while (b != 0)
    {
        int64_t tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}

struct fraction
{
    fraction() = default;
    fraction(int64_t nom, int64_t denom)
        : nom(nom), denom(denom), full_denom(denom)
    {
        normalize();
    }

    void normalize()
    {
        auto g = gcd(nom, denom);
        nom /= g;
        denom /= g;
    }

    int64_t nom;
    int denom;
    int full_denom;
};

inline bool operator==(const fraction& left, const fraction& right)
{
    return left.nom == right.nom && left.denom == right.denom;
}

inline bool operator<(const fraction& left, const fraction& right)
{
    auto left_w = left.nom * right.denom;
    auto right_w = right.nom * left.denom;
    return left_w < right_w || left_w == right_w && left.full_denom < right.full_denom;
}

inline bool operator<(int64_t left, const fraction& right)
{
    return left * right.denom < right.nom;
}

inline int msb(uint32_t x) {
    return 32 - __lzcnt(x);
}

void run_test(size_t t)
{
    int64_t n;
    cin >> n;
    vector<uint32_t> v(n);
    cin >> v;
    int subsequent = 0;
    int prev = -1;
    for (auto x : v) {
        if (msb(x) == prev) {
            ++subsequent;
        }
        else
        {
            subsequent = 1;
        }
        if (subsequent == 3) {
            cout << 1 << endl;
            return;
        }
    }
    vector<uint32_t> xors = { 0 };
    xors.insert(xors.end(), v.begin(), v.end());
    for (int i = 1; i < n; ++i) {
        xors[i] ^= xors[i - 1];
    }
    int count = numeric_limits<int>::max();
    for (int i = 0; i + 2 < n; ++i)
    {
        for (int j = i + 1; j + 1 < n; ++j) {
            for (int k = j + 1; k < n; ++k) {
                auto left_part = xors[j] ^ xors[i];
                auto right_part = xors[k] ^ xors[j];
                if (left_part > right_part) {
                    count = min(count, k - i - 2);
                }
            }
        }
    }
    cout << (count == numeric_limits<int>::max() ? -1 : count) << endl;
}

int main() {
    size_t T;
    //cin >> T;
    T = 1;
    for (size_t t = 1; t <= T; ++t) {
        run_test(t);
    }
}

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+100;
const int inf=2e9+10;
int read()
{
	int ans=0;bool f=0;char ch=getchar();
	while(ch<'0' or ch>'9'){if(ch=='-')f=1;ch=getchar();}
	while(ch>='0' and ch<='9'){ans=(ans<<1)+(ans<<3)+(ch^48);ch=getchar();}
	return f?~ans+1:ans;
}
int n,a[maxn],sum[maxn],ans,flag;
int qjhe(int x,int y)
{
	return sum[y]^sum[x-1];
}
int main()
{
    n=read();
    for(int i=1;i<=n;++i)
    a[i]=read(),sum[i]=sum[i-1]^a[i];
    a[n+1]=inf;
    ans=1;
    for(int i=1;i+ans<=n;++i)
    if(qjhe(i,i+ans)<a[i-1] or qjhe(i,i+ans)>a[i+ans+1])
    flag=1;
    if(flag)
    return cout<<ans<<endl,0;
    ans=inf;
    for(int i=1;i<=n;++i)
    for(int j=i+1;j<=n;++j)
    for(int k=j+1;k<=n;++k)
    for(int l=k+1;l<=n;++l)
    if(qjhe(i,j)>qjhe(k,l))
    ans=min(ans,j-i+l-k);
    if(ans!=inf)
    cout<<ans<<endl;
    else
    cout<<-1<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int minSteps(vector<int>& arr, int n) {
	if (n >= 200) return 1;
	if (n <= 2) return -1;
	vector<int> b(n + 1);
	for (int i = 0; i < n; ++i) {
		b[i + 1] = b[i] ^ arr[i];
	}
	int res = INT_MAX;
	for (int l = 1; l <= n; ++l) {
		for (int i = 1; i < n - l; ++i) {
			int j = i + l;
			for (int k = i; k < j; ++k) {
				int left = b[i - 1] ^ b[k], right = b[k] ^ b[j];
				if (left > right) {
					res = min(res, j - i - 1);
				}
			}
		}
	}
	return res == INT_MAX ? -1 : res;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;
	vector<int> arr(n, 0);
	for (int i = 0; i < n; ++i) cin >> arr[i];
	cout << minSteps(arr, n) << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e6+10;
const int mod=1e9+7;
ll t,n,cnt,k,p,x,y;
ll a[maxn];
ll flag;
ll b[maxn];
int main()
{
    cin>>n;
    if(n>=1000)
    {
        cout<<1<<endl;
        return 0;
    }
    b[0]=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        b[i]=b[i-1]^a[i];
    }
    ll min1=mod;
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            ll l=j-i+1;
            ll s=b[j]^b[i-1];
            if(i!=1)
            {
                if(s<a[i-1])
                {
                    min1=min(min1,l);
                }
            }
            if(j!=n)
            {
                if(s>a[j+1])
                {
                    min1=min(min1,l);
                }
            }
        }
    }
    if(min1==mod)
    {
        cout<<-1<<endl;
    }
    else
        cout<<min1-1<<endl;
    return 0;
}

#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define ff first
#define ss second

using namespace std;
typedef long long ll;
#define int ll
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;

ifstream iredirect;
ofstream oredirect;
const string file = "data";
const ll INF = 9223372036854775807ll;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, 1, -1}, inf = 2147483647;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int rnd(int l, int r)
{
	return uniform_int_distribution<int>(l, r)(rng);
}

void prepare_IO()
{
	#ifndef WATER_ADDICT
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
		cout.tie(NULL);
	#else
		iredirect.open(file+".in");
		cin.rdbuf(iredirect.rdbuf());
		// oredirect.open(file+".out");
		// cout.rdbuf(oredirect.rdbuf());
	#endif
}

struct trie{
	int val, maxpos;
	trie *f[2];

	trie() {
		f[0] = f[1] = nullptr;
		val = 0;
		maxpos = 0;
	}

	trie(int x) {
		f[0] = f[1] = nullptr;
		val = x;
		maxpos = 0;
	}

	void add(int x, int j, int pos) {
		maxpos = pos;
		if (j == -1) {
			val = x;
			return;
		}
		if (x&(1<<j)) {
			if (f[1] == nullptr)
				f[1] = new trie();
			f[1]->add(x, j-1, pos);
		}else {
			if (f[0] == nullptr)
				f[0] = new trie();
			f[0]->add(x, j-1, pos);
		}
	}

	int best(int x, int y, int j) { //x - head of prefix as prefix, y - checking against
		if (y&(1<<j)) {
			if (x&(1<<j)) {
				if (f[0] == nullptr)
					return -10;
				return f[0]->best(x, y, j-1);
			}else {
				if (f[1] == nullptr)
					return -10;
				return f[1]->best(x, y, j-1);
			}
		}else {
			if (x&(1<<j)) {
				int now = -10;
				if (f[0] != nullptr)
					now = max(now, f[0]->maxpos);
				if (f[1] != nullptr)
					now = max(now, f[1]->best(x, y, j-1));
				return now;
			}else {
				int now = -10;
				if (f[1] != nullptr)
					now = max(now, f[1]->maxpos);
				if (f[0] != nullptr)
					now = max(now, f[0]->best(x, y, j-1));
				return now;
			}
		}
		return -10;
	}
	~trie() {
		delete f[0];
		delete f[1];
	}
};

int solve(vector<int> &v)
{
	int n = v.size();
	vector<int> pr(n);
	for (int i = 0; i < n; ++i)
		pr[i] = (i == 0 ? 0 : pr[i-1])^v[i];
	for (int i = 0; i+2 < n; ++i)
		if (v[i] > (v[i+1]^v[i+2]))
			return 1;
	int ans = -1;
	for (int i = 0; i < n; ++i)
		for (int j = i+3; j < n && j-i <= 70; ++j)
			if (v[i] > (pr[i]^pr[j]))
				if (ans == -1)
					ans = j-i-1;
				else ans = min(ans, j-i-1);
	trie *rad = new trie;
	rad->add(0, 30, -1);
	for (int i = 1; i < n; ++i) {
		int pos = rad->best(pr[i-1], v[i], 30);
		if (pos != -10) {
			if (ans == -1)
				ans = i-pos-2;
			else ans = min(ans, i-pos-2);
		}
		rad->add(pr[i-1], 30, i-1);
	}
	delete rad;
	return ans;
}

signed main()
{
	prepare_IO();
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	cout << solve(v) << "\n";
	return 0;
}

//
//  main.cpp
//  cp
//
//  Created by Shivam Gor on 21/11/20.
//

#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define hell 1000000007
#define hell1 1000000006
#define pb push_back
#define x first
#define y second
#define MAXL 100005
#define pll pair<ll,ll>
#define pii pair<int,int>
#define L LLONG_MAX
#define all(v) (v).begin(),(v).end()
#define tcFile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
//vector<int>prime(15000005,0);
ll mM(ll a,ll b,ll p=hell){ll res = 0;if(a>=p)a %= p;while(b){if (b & 1ll)res = (res + a);if(res>=p) res%= p;a = (2 * a); if(a>=p)a%=p;b >>= 1ll;}return res;}
ll fpow(ll x,ll y,ll p=hell){if(x>=p)x=x%p;ll res=1;while(y){if(y&1ll)res*=x;if(res<0)res+=p;if(res>=p)res%=p;y=y>>1ll;x*=x;if(x<0)x+=p;if(x>=p)x%=p;}return res;}
ll inv(ll n,ll p=hell){return fpow(n,p-2,p);}
ll modmul(ll x,ll y,ll p = hell){if(x<0)x+=p;if(x>=p)x%=p;if(y<0)y+=p;if(y>=p)y%=p;return (x*y)%p;}
ll modadd(ll x,ll y,ll p = hell){if(x<0)x+=p;if(x>=p)x%=p;if(y<0)y+=p;if(y>=p)y%=p;ll temp=x+y;if(temp>=p)temp%=p;return temp;}
/*void sieve(){
    prime[0] = -1;
    prime[1] = 0;
    for(int i=2;i<=15000000;i++)
        if(!prime[i])
            for(int j=i;j<=15000000;j+=i)
                if(!prime[j])
                    prime[j] = i;
}*/

vector<ll>tree(400020),arr(100005);
int n,k;
void build(int node, int start, int end){//1,1,n
    if(start == end)
        tree[node] = arr[start];
    else{
        int mid = (start + end) / 2;
        build(2*node, start, mid);
        build(2*node+1, mid+1, end);
        tree[node] = tree[2*node] ^ tree[2*node+1];
    }
}
ll query(int node, int start, int end, int l, int r){//1,1,n,l,r            l,r is 1 based
    //cout << node << " " << start << " " << end << " " << l << " " << r << "\n";
    if(r < start || end < l)
        return 0;
    if(l <= start && end <= r)
        return tree[node];
    int mid = (start + end) / 2;
    ll p1 = query(2*node, start, mid, l, r);
    ll p2 = query(2*node+1, mid+1, end, l, r);
    return (p1 ^ p2);
}

int main(){
    ios
    int t = 1,tc = 0;
    //cin >> t;
    while(t--){
        cin >> n;
        for (int i = 1; i <= n; i++)
        cin >> arr[i];
        build(1, 1, n);
        int lo = 1, hi = n-1, ans = INT_MAX;
        while (lo <= hi) {
            int mid = (lo+hi)/2;
            bool ok = false;
            //cout << mid << "\n";
            for (int i = mid; i < n; i++) {
                int l = i-mid+1, r = i+1;
                ll val = query(1, 1, n, l, r);
                //cout << l << " " << r << " " << val << "\n";
                if (l > 1) {
                    if (val < arr[l-1]) {
                        ok = true;
                        break;
                    }
                }
                if (r < n) {
                    if (val > arr[r+1]) {
                        ok = true;
                        break;
                    }
                }
            }
            //cout << ok << "\n";
            if (ok) {
                ans = min(ans, mid);
                hi = mid-1;
            } else {
                lo = mid+1;
            }
        }
        if (ans >= (n-1))
            cout << "-1\n";
        else
            cout << ans << "\n";

    }
}

//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<bitset>
#include<map>
#include<cmath>
#include<queue>
#include<set>
#include<cmath>
#include<vector>
#include<cstring>
#include<set>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define LL __int128
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define PI acos(-1)
#define ull unsigned long long
const int maxn = 1e5 + 9;
const int MOD = 1000000007;
int mod = 999998639;
ll exgcd(ll a,ll b,ll &x,ll &y){if(b==0) {x=1,y=0;return a;}ll d=exgcd(b,a%b,x,y);ll z=x;x=y,y=z-y*(a/b);return d;}
inline ll qpow(ll b, ll e, ll m = MOD) { ll a = 1; for (; e; e >>= 1, b = b * b % m)if (e & 1)a = a * b % m; return a; }
//inline void print(__int128 x){if (x < 0){putchar('-');x = -x;}if (x > 9)print(x / 10);putchar(x % 10 + '0');}
//LL exgcd(LL a,LL b,LL &x,LL &y){if(b==0) {x=1,y=0;return a;}LL d=exgcd(b,a%b,x,y);LL z=x;x=y,y=z-y*(a/b);return d;}
//inline LL qpow(LL b, LL e, LL m = MOD) { LL a = 1; for (; e; e >>= 1, b = b * b % m)if (e & 1)a = a * b % m; return a; }
int a[maxn];
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
		}
		int ans=inf;
		for(int i=1;i<=n;i++)
		{
			int temp=a[i];
			for(int j=1;j<=30&&i+j<n;j++)
			{
				temp^=a[i+j];
				if(temp>a[i+j+1])
				{
					ans=min(ans,j);
					break;
				}
			}
		}
		if(ans==inf) printf("-1\n");
		else printf("%d\n",ans);
	}
}

#include <bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define pb push_back
#define db double
#define int ll
using namespace std;
const int maxn = 200001, inf = 2147483647;
const ll mod = 1 ? 998244353 : 1000000007, linf = 9223372036854775807;
const double pi = acos(-1);
inline ll mi(ll a, ll b, ll mm = mod) { a %= mm; ll u = 1; while (b) { if (b & 1)u = u * a % mm; a = a * a % mm, b >>= 1; }return u; }
inline ll gcd(ll a, ll b) { ll c = a % b; while (c)a = b, b = c, c = a % b; return b; }
inline void mem(int* a, int p = 0, int len = maxn) { for (int i = 0; i < len; i++)a[i] = p; }
struct p {}e[maxn];
static bool cmp(int i, int j) { return i > j; };
int t, n, m, a[maxn], b[maxn], x, su, y, xx;
signed main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);//sf和cin混用会出错
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	a[0] = -1, a[n + 1] = inf;
	for (int mm = 0; mm < 40; mm++)
		for (int i = 1; i < n - mm; i++)
		{
			int u = 0;
			for (int j = i, jj = 0; jj <= mm + 1; jj++, j++)
				u ^= a[j];
			if (u<a[i - 1] || u>a[i + mm + 2])
			{
				cout << mm + 1;
				return 0;
			}
			for (int jj = i; jj < mm + 1; jj++)
			{
				int ua = 0, ub = 0;
				for (int ii = i; ii <= jj; ii++)
					ua ^= a[ii];
				for (int jjj = jj + 1; jjj <= mm + 1; jjj++)
					ub ^= a[jjj];
				if (ua > ub)
				{
					cout << mm;
					return 0;
				}
			}
		}
	cout << -1;
}

#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int n,a[maxn],pre[maxn];

int main()
{
	n=read(); rep(i,1,n) a[i]=read(),pre[i]=pre[i-1]^a[i];
	int ans=-1;
	rep(l,2,50)
	{
		rep(i,l,n-1) if((pre[i]^pre[i-l])>a[i+1])
		{
			ans=l-1;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

#include<bits/stdc++.h>
#define FOR(i,l,r) for(int i=l;i<=r;i++)
#define ROF(i,l,r) for(int i=l;i>=r;i--)
#define lson k<<1,l,mid
#define rson k<<1|1,mid+1,r
#define r(x) read(x)
#define rr(x,y) read(x);read(y)
#define rrr(x,y,z) read(x);read(y);read(z)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define sss(str) scanf("%s",str+1)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N = 2e5 + 5;
const int M = 2e3 + 5;
const int mod = 998244353;
const int INF = 2e9;
const double eps = 1e-7;
const double pi = acos(-1);
template <class T>
inline void read(T &x) {
    char c;x = 1;
    while ((c = getchar()) < '0' || c > '9') if (c == '-') x = -1;
    T res = c - '0';
    while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
    x *= res;
}
int n,m;
char str[N];
int f[N],g[M];
int sum[N];
bool check1()
{
    for(int i=2;i<=n;i++){
        int now=(f[i]^f[i-1]);
        if(i<n){
            if(now>f[i+1]) return 1;
        }
        if(i>2){
            if(now<f[i-2]) return 1;
        }
    }
    return 0;
}
void solve(int cas)
{
    r(n);
    FOR(i,0,30) g[i]=-1;
    FOR(i,1,n){
        r(f[i]);
        sum[i]=sum[i-1]^f[i];
        for(int j=30;j>=0;j--){
            if((f[i]>>j)&1){
                if(g[j]==-1){
                    g[j]=i;
                }
                break;
            }
        }
    }
    if(n==2){
        cout<<-1<<endl;
        return ;
    }
    if(check1()){
        cout<<1<<endl;
        return ;
    }
    int ans=INF;
    FOR(i,0,30){
        int pos=g[i];
        if(pos==-1||pos==n) continue;
        ROF(j,pos,1){
            int tmp=sum[pos]^sum[j-1];
            if(tmp>f[pos+1]){
                ans=min(ans,pos-j);
                break;
            }
        }
    }
    if(ans==INF) ans=-1;
    cout<<ans<<endl;
}
int main()
{
    int t;
//    r(t);
    t=1;
//    init();
    FOR(i,1,t){
        solve(i);
    }
    return 0;
}

//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
template<typename T>void rearrange(vector<ll>&ord, vector<T>&v){
  auto tmp = v;
  for(int i=0;i<tmp.size();i++)v[i] = tmp[ord[i]];
}
template<typename Head, typename... Tail>void rearrange(vector<ll>&ord,Head&& head, Tail&&... tail){
  rearrange(ord, head);
  rearrange(ord, tail...);
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int popcount(ll x){return __builtin_popcountll(x);};
int poplow(ll x){return __builtin_ctzll(x);};
int pophigh(ll x){return 63 - __builtin_clzll(x);};

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n);
  vector<ll>b(n);
  rep(i,0,n){
    cin>>a[i];
    b[i]=pophigh(a[i]);
  }
  res=INF;
  ll sz=30;
  vector<ll>pre(sz,0);
  vector<ll>pren(sz,0);
  vector<ll>cum(n+1);
  rep(i,0,n-1){
    cum[i+1]=cum[i]^a[i];
    for(auto &pp:{pre,pren}){
      for(auto j:pp){
        if((cum[i+1]^cum[j])>a[i+1]){
          //out<<cum[i+1] spa i spa j spa cum[j] spa a[i+1]<<endl;
          chmin(res,i-j);
        }
      }
    }
    rep(j,0,30){
      if(cum[i+1]&1<<j)pre[j]=i+1;
      else pren[j]=i+1;
    }
  }
  ans(res==INF,-1,res);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e6+10;
const int mod=1e9+7;
ll t,n,cnt,k,p,x,y;
ll a[maxn];
ll flag;
ll b[maxn];
int main()
{
    cin>>n;
    if(n>=100)
    {
        cout<<1<<endl;
        return 0;
    }
    b[0]=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        b[i]=b[i-1]^a[i];
    }
    ll min1=mod;
    for(int i=1;i<=n;i++)
    {
        for (int j = i + 1; j <= n; j++) {
            for (int k = j; k <= n; k++) {
                if (b[k]^b[j]<a[i])
                    min1 = min(min1, 1ll*(k - j + 1));
            }
        }
    }
    if(min1==mod)
    {
        cout<<-1<<endl;
    }
    else
        cout<<min1<<endl;
    return 0;
}

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define rep(i,l,r) for(int i = (l); i <= (r); i++)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vt vector
#define pb push_back
#define F first
#define S second
// bp,dp,gd,prt
const int N = 1e5 + 10;
int n,a[N];

void solve() {
	cin >> n;
	rep(i,1,n) cin >> a[i];
	int re = 1 + n;
	rep(i,2,n) {
		int x = a[i - 1];
		for(int j = i - 2; j >= 1; j--) {
			x ^= a[j];
			if(x > a[i]) {
				re = min(re,i - j - 1);
				break;
			}
		}
	}
	cout << (re >= 1 + n ? -1 : re);
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int T = 1;
	//cin >> T;
	while (T--) {
		solve();
	}
}

#include <algorithm>
#include <iostream>
#include <cassert>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
using namespace std;
using ll = long long;
int a[100002], f[100002], xr[100002];
int cntf(int x)
{
	int q = 0;
	while (x)
	{
		x >>= 1;
		q++;
	}
	return q;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		f[i] = cntf(a[i]);
	}
	for (int i = 1; i < n - 1; i++)
	{
		if (a[i] == a[i + 1]) {
			cout << 1 << '\n'; return 0;
		}
		if (f[i] == f[i - 1] && f[i] == f[i + 1])
		{
			cout << 1 << '\n'; return 0;
		}
	}
	int ans = 10'000'000;
	for (int i = 0; i < n - 1; i++)
	{
			int xl = a[i];
			for (int l = i - 1; l >= 0; l--)
			{
				xl ^= a[l];
				int xr = a[i + 1];
				if (xl > a[i + 1]) ans = min(ans, i - l);
				for (int r = i + 2; r < n; r++)
				{
					if (xr < a[i]) ans = min(ans, r - i - 1);
					xr ^= a[r];
					if (xl > xr) ans = min(ans, i - l + r - i - 1);
				}
			}
	}
	if (ans<10'000'000)cout << ans << '\n';
	else cout << -1 << '\n';
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

const int Max = 2e5 + 10;
const int Mod = 1e9 + 7;
const ll Inf = 1LL << 62;

ll seg[Max * 4];
ll ar[Max];

void build(int node, int l, int r) {
	if(l == r) {
		seg[node] = ar[l];
		return;
	}

	int mid = (l + r) >> 1;
	int lf = node * 2;
	int rt = node * 2 + 1;
	build(lf, l, mid);
	build(rt, mid + 1, r);
	seg[node] = seg[lf] ^ seg[rt];
}

ll query(int node, int l, int r, int L, int R) {
	if(R < l || L > r) {
		return 0;
	}

	if(L <= l && r <= R) {
		return seg[node];
	}

	int mid = (l + r) >> 1;
	ll u = query(node * 2, l, mid, L, R);
	ll v = query(node * 2 + 1, mid + 1, r, L, R);
	return u ^ v;
}

int main(int argc, char const *argv[]) {
	int n;
	cin >> n;

	for (int i = 1; i <= n; i++) {
		cin >> ar[i];
	}

	build(1, 1, n);
	ll ans = Inf;

	for (ll i = 1; i <= n; i++) {
		ll l = 1, r = i - 1;

	//	if (query(1, 1, n, 1, i - 1) > ar[i]) {
			ll x = 1;
			ll cnt = 0;
			for(int j = i - 1; j >= 1; j--) {
				if (j == i - 1) {
					x = ar[j];
				} else {
					x ^= ar[j];
				}
				cnt++;
				if(x > ar[i]) {
					ans = min(ans, cnt);
					break;
				}
			}
	//	}
	}

	for (ll i = 1; i <= n; i++) {
		ll l = i + 1, r = n;
	//	if (query(1, 1, n, i + 1, n) < ar[i]) {
			ll x = 1;
			ll cnt = 0;
			for(int j = i + 1; j <= n; j++) {
				if (j == i + 1) {
					x = ar[j];
				} else {
					x ^= ar[j];
				}
				cnt++;
				if(x < ar[i]) {
					ans = min(ans, cnt);
					break;
				}
			}
		//}
	}

	if (ans == Inf) {
		ans = 0;
	}

	cout << ans - 1 << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int n,a[100005];
int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
        cin>>a[i];
    int ans=1000;
    for (int i=1;i<=n;i++)
    {
        if (i!=1&&i!=n)
        {
            int tmp=a[i]^a[i-1];
            if (tmp>a[i+1]) ans=min(ans,1);
            tmp=a[i]^a[i+1];
            if (tmp<a[i-1]) ans=min(ans,1);
        }
        if (i+2<=n&&i>=2)
        {
            int tmp1=a[i]^a[i-1];
            int tmp2=a[i+1]^a[i+2];
            if (tmp1>tmp2) ans=min(ans,2);
        }
    }
    if (ans>2) puts("-1");
    else cout<<ans;
}

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define M ll(998244353)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e9)
#define el '\n'
#define pii pair <ll, ll>
#define all(x) (x).begin(), (x).end()
#define arr_all(x, n) (x + 1), (x + 1 + n)
#define vi vector<int>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 1e5 + 500;

int a[N], bt[N];
int i, n, j;

int main()
{
    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(0);
    iostream::sync_with_stdio(0);
////
//    in("umbrella.in");
//    out("umbrella.out");

    cin >> n;

    for (i = 1; i <= n; i++)
        {
            cin >> a[i];
            int x = a[i];
            bt[i] = 0;

            while (x)
            {
                x >>= 1;
                bt[i]++;
            }
        }

    for (i = 1; i <= n; i++)
    {
        if (i + 2 <= n && (a[i] ^ a[i + 1]) > a[i + 2])
        {
            cout << "1";
            return 0;
        }

        if (i - 1 >= 1 && (a[i] ^ a[i + 1]) < a[i - 1])
        {
            cout << "1";
            return 0;
        }
    }

    for (i = 1; i <= n - 2; i++)
        if (bt[i] == bt[i + 1] && bt[i + 1] == bt[i + 2])
    {
        cout << "2" << el;
        return 0;
    }

    int ans = 1e9;

    a[0] = 0;

    for (i = 1; i <= n; i++)
    {
        int xr = a[i];
        for (j = i + 1; j <= n; j++)
        {
            xr ^= a[j];

            if (j + 1 <= n && xr > a[j + 1])
              ans = min(ans, j - i);

            if (i > 1 && xr < a[i - 1])
                ans = min(ans, j - i);
        }
    }

    if (ans == 1e9)
        cout << "-1";
    else
        cout << ans;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define int long long
using namespace std;
using namespace __gnu_pbds;

// typedef tree<
// int,
// null_type,
// less<int>,
// rb_tree_tag,
// tree_order_statistics_node_update>
// ordered_set;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> mass(n);
    for (int i = 0; i < n; i++){
        cin >> mass[i];
    }
    vector<int> greater_pow(n);
    for (int i = 0; i < n; i++){
        int x = mass[i];
        int cur_pow = 0;
        while (x){
            cur_pow++;
            x /= 2;
        }
        greater_pow[i] = cur_pow;
    }
    for (int i = 0; i < n - 3; i++){
        if (greater_pow[i] == greater_pow[i + 1] && greater_pow[i + 1] == greater_pow[i + 2]){
            cout << 1 << endl;
            return 0;
        }
    }
    mass.push_back(1e18);
    mass.insert(mass.begin(), -1);
    for (int length = 1; length < n - 1; length++){
        for (int l = 1; l <= n - length + 1; l++){
            int cur_xor = 0;
            for (int i = l; i < l + length; i++){
                cur_xor ^= mass[i];
            }
            if (cur_xor < mass[l - 1] || cur_xor > mass[l + length]){
                cout << length - 1<< endl;
                return 0;
            }
        }
    }
    cout << -1  << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//typedef __int128 INT;
typedef double db;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> PII;
#define so sizeof
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define fi first
#define se second
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
const db esp=1e-5;
const int N=1e5+10,M=25e3+10,Max=500,inf=0x3f3f3f3f,mod=2147483648ll;
const ll INF=0x3f3f3f3f3f3f3f3f;

int n,a[N],ps[N];

void work(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    if(n==2){
        puts("-1"); return ;
    }
    for(int i=1;i<=n;i++)
        ps[i]=ps[i-1]^a[i];
    for(int len=1;len<=64;len++){
        for(int i=1;i+len<=n;i++){
            int res=ps[i+len]^ps[i-1];
            if(i==1){
                if(res>a[i+len+1]) { printf("%d\n", len); return ; }
            }else if(i+len==n){
                if(res<a[i-1]) { printf("%d\n", len); return ;}
            }else{
                if(res<a[i-1]||res>a[i+len+1]) { printf("%d\n",len); return ;}
            }
        }
    }
    puts("-1");
    return ;
}

int main(){
//freopen("C:\\Users\\lenovo\\Desktop\\in.txt","r",stdin);
//    int t;
//    scanf("%d",&t);
//    for(int i=1;i<=t;i++)
//        printf("Case #%d: ",i),
        work();
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1e5+10;
int a[maxn],pre,las;
int tr[maxn*32][2],root[maxn],tot=0;
void insert(int x,int k)
{
	int rt=0;
	for(int i=31;i>=0;i--){
		int id=0;
		if(x&(1<<i))	id=1;
		if(tr[rt][id]==0)	tr[rt][id]=++tot;
		rt=tr[rt][id];root[rt]=k;
	}
}
int check(int x,int y)
{
	int rt=0;
	for(int i=31;i>=0;i--){
		int d1=0,d2=0;
		if(x&(1<<i))	d1=1;
		if(y&(1<<i))	d2=1;
		if(d2){
			if(d1){
				if(tr[rt][0]==0)	return 1e9;
				rt=tr[rt][0];
			}
			else{
				if(tr[rt][1]==0)	return 1e9;
				rt=tr[rt][1];
			}
		}else{
			if(d1){
				if(tr[rt][0])		return root[tr[rt][0]];
				if(tr[rt][1]==0)	return 1e9;
				rt=tr[rt][1];
			}else{
				if(tr[rt][1])		return root[tr[rt][1]];
				if(tr[rt][0]==0)	return 1e9;
				rt=tr[rt][0];
			}
		}
	}
	return root[rt];
}
int check1(int x,int y)
{
	int rt=0;
	for(int i=31;i>=0;i--){
		int d1=0,d2=0;
		if(x&(1<<i))	d1=1;
		if(y&(1<<i))	d2=1;
		if(d2==0){
			if(d1){
				if(tr[rt][1]==0)	return 1e9;
				rt=tr[rt][1];
			}
			else{
				if(tr[rt][0]==0)	return 1e9;
				rt=tr[rt][0];
			}
		}else{
			if(d1==0){
				if(tr[rt][0])		return root[tr[rt][0]];
				if(tr[rt][1]==0)	return 1e9;
				rt=tr[rt][1];
			}else{
				if(tr[rt][1])		return root[tr[rt][1]];
				if(tr[rt][0]==0)	return 1e9;
				rt=tr[rt][0];
			}
		}
	}
	return root[rt];
}
signed main()
{
	int n;scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	int ans=1e9;
	insert(0,0);
	for(int i=1;i<n;i++){
		pre=pre^a[i];
		if(i!=1){
			int rec=check(pre,a[i+1]+1);
			//cout<<i<<" "<<rec<<endl;
			ans=min(ans,abs(i-rec));
		}
		insert(pre,i);
	}
	memset(tr,0,sizeof tr);memset(root,0,sizeof root);tot=0;
	insert(0,n+1);
	for(int i=n;i>1;i--){
		las=las^a[i];
		if(i!=n){
			int rec=check1(las,a[i-1]+1);//a[i-1]>a[i]
			ans=min(ans,abs(i-rec));
		}
		insert(las,i);
	}
	ans--;
	if(ans>n){
		printf("-1\n");return 0;
	}
	cout<<ans<<endl;
}
/*
4
2 5 6 8
*/

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

//const int mod = 1e9 + 7
//const int mod = 998244353;

const int maxn = 1e5 + 5;

ll a[maxn];

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    if (n >= 32 * 3) {
        cout << 1 << endl;
        return 0;
    }

    int ans = 1e9;
    for (int i = 1; i <= n; i++) {
        int now = a[i];
        for (int j = i + 1; j < n; j++) {
            now ^= a[j];
            if (now > a[i - 1] || now < a[j + 1]) {
                ans = min(ans, j - i);
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

#pragma GCC optimize ("Ofast")
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <set>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

using namespace __gnu_pbds;

vector <int> gr[(int)(33)];

using ordered_set = tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update>;
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector <int> a(n);
    for (int i = 0;i < n;i++)
        cin>>a[i];
    if (n > 32) {
        cout<<1;
        return 0;
    }
    int ans = 2e9;
    vector <int> pref(n);
    for (int i = 0;i < n;i++)
        if (i==0) pref[i] = a[i];
    else pref[i] = pref[i-1] ^ a[i];
    for (int i = 0;i < n;i++)
    {
        for (int j = i + 1;j < n;j++)
        {
            for (int q = j + 1;q < n;q++)
            {
                int cur_xor_1 = pref[j];
                if (i) cur_xor_1^=pref[i-1];
                int cur_xor_2 = pref[q];
                cur_xor_2^=pref[j];
                if (cur_xor_1 > cur_xor_2) ans = min(ans,j - i + q - j - 1);
            }
        }
    }
    for (int i = 1;i < n;i++)
    {
        for (int j = i + 1;j < n;j++)
        {
            for (int q = i;q >= 0;q--)
            {
                int cur_xor_1 = pref[j];
                if (i) cur_xor_1^=pref[i-1];
                int cur_xor_2 = pref[i-1];
                if (q) cur_xor_2^=pref[q - 1];
                //if (cur_xor_2 > cur_xor_1) cout<<i<<" "<<j<<" "<<q<<" "<<cur_xor_2<<" "<<cur_xor_1<<'\n';
                if (cur_xor_2 > cur_xor_1) ans = min(ans,j - i + i - q - 1);
            }
        }
    }
    if (ans==2e9) ans = -1;
    cout<<ans;
}

//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define PI              acos(-1.0)
#define No              cout<<"No\n"
#define Yes             cout<<"Yes\n"
#define no              cout<<"no\n"
#define yes             cout<<"yes\n"
#define NO              cout<<"NO\n"
#define YES             cout<<"YES\n"
#define MOD             (int)1000000007
#define int             long long
#define ll              long long
#define pii             pair<int, int>
#define fi               first
#define se              second
#define sf(a)           scanf("%lld", &a)
#define pf(a)           printf("%lld ", a)
#define case(a)         cout<<"Case "<<a<<": ";
#define FASTIO          ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define pb              push_back
#define mem(arr)        memset(arr, 0, sizeof(arr))
#define mem1(arr)       memset(arr, -1, sizeof(arr))
#define all(a)          a.begin(),a.end()
#define f(i,a,b)        for (int i = a; i<=b; i++)
#define fr(i,a,b)       for (int i = a; i>=b; i--)
#define rr              return 0
#define prec(n)         fixed<<setprecision(n)
#define maxpq           priority_queue<int>
#define minpq           priority_queue<int, vector<int>, greater<int> >
#define inf             (int)(1e18)
#define vi              vector<int>
#define endl            "\n"
#define vii             vector<pii>
#define sz(s)           s.size()
#define bits(n)         __builtin_popcount(n)
#define lcm(a,b)        (a*(b/gcd(a,b)))
#define MX              500005

int gcd(int a, int b)   {return __gcd(a,b);}

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n or (1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

const double eps = 1e-9;

int dx[5] = {+1, +0, -1, -0};
int dy[5] = {+0, +1, -0, -1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

bool Equal(double x, double y)
{
    return fabs(x-y)<eps; ///x==y
}

bool Greater(double x, double y)
{
    return x-eps>y; ///x>y
}

bool Lesser(double x, double y)
{
    return x+eps<y; ///x<y
}

struct point
{
    double x, y, ang;
};

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << '\n'; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << " "; err(++it, args...); }

///Write what you need -->
/// nt, ft, kmp, tri, sufarr, ub_lb, lis
/// dsu

///Template Ends Here////////////////////////////

signed main()
{
//    root = new trinode();
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    FASTIO

    int n;
    cin>>n;

    int a[n+1];
    f(i, 1, n){
        cin>>a[i];
    }

//    for(int k = 3; k<=200; k++){
//        fr(i, n, k){
//            int x = 0;
//            f(j, 0, k-2){
//                x ^= a[i-j];
//            }
////            error(k, i, x);
//            if(x < a[i-k+1]){
//                cout<<k-3+1;
//                rr;
//            }
//        }
//
//        f(i, 1, n-k){
//            int x = 0;
//            f(j, 0, k-2){
//                x ^= a[i+j];
//            }
////            error(k, i, x);
//            if(x > a[i+k-1]){
//                cout<<k-3+1;
//                rr;
//            }
//        }
//
//    }

    int ans = inf;
    f(l, 1, 10){
        f(r, 1, 10){
            f(i, l, n-r){
                int x=0, y=0;
                fr(k, i, i-l+1) x^=a[k];
                f(k, i+1, i+r) y^=a[k];

                if(x>y){
//                    error(l, r, x, y, i);
                    ans = min(ans, l+r-2);
                }
            }
        }
    }

    if(ans == inf) ans = -1;
    cout<<ans;

//    tridel(root);
}

#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;

#pragma GCC optimize("O3")
#ifdef LOCAL
#include "/Users/lbjlc/Desktop/coding/debug_utils.h"
#else
#define print(...) ;
#define printn(...) ;
#define printg(...) ;
#define fprint(...) ;
#define fprintn(...) ;
#endif

#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define maxi(x, y) x = max(x, y)
#define mini(x, y) x = min(x, y)
// long long fact(long long n) { if(!n) return 1; return n*fact(n-1); }
// #define endl '\n'
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int get_random() {
    static uniform_int_distribution<int> dist(0, 1e9 + 6);
    return dist(rng);
}
#define solve_testcase int T;cin>>T;for(int t=1;t<=T;t++){solve(t);}

typedef unsigned long long ull;
typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<long long> vll;
#define bd(type,op,val) bind(op<type>(), std::placeholders::_1, val)

template<class T>
void make_unique(T & v) {
    sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
}
int geti() { int x; cin >> x; return x; }
long long getll() { long long x; cin >> x; return x; }
double getd() { double x; cin >> x; return x; }
// pair<int, int> a(geti(), geti()) does not work
// pair<int, int> a({geti(), geti()}) works, since it uses initializer.

const int MAXN = 3e5 + 100;

void solve(int tt) {
    // cout<<"Case #"<<tt<<": ";
}

int main(int argc, char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // solve_testcase;

    int n;
    cin>>n;
    vi a(n);
    rep(i,0,n)cin>>a[i];

    if(n<100) {
    	int res=1e9;
    	rep(i,0,n) {
    		rep(j,i+1,n) {
    			int cur=0;
    			rep(k,i,j+1) {
    				cur^=a[k];
    			}
    			if(i>0&&cur<a[i-1]) mini(res,j-i+1);
    			if(j+1<n&&cur>a[j+1]) mini(res,j-i+1);
    		}
    	}
    	if(res<1e9)
	    	cout<<res-1<<endl;
	    else
	    	cout<<-1<<endl;
    }
    else {
    	cout<<1<<endl;
    }

    return 0;
}

#include <bits/stdc++.h>

#define ibase ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define fix10 fixed << setprecision(10)

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair <int, int>;
using pll = pair <ll, ll>;

mt19937 rnd(time(0));

int main(){
    ibase;
    int n, mn = 1e9 + 7;
    cin >> n;
    vector <int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    if(n >= 100){
        cout << 1;
        return 0;
    }
    for(int i = 0; i < n; ++i){
        if(i != n - 1){
            int g = a[i + 1], j = i + 2;
            while(j < n and g > a[i]){
                g ^= a[j];
                ++j;
            }
            if(g < a[i]){
                mn = min(mn, j - i - 2);
            }
        }
        if(i != 0){
            int g = a[i - 1], j = i - 2;
            while(j >= 0 and g < a[i]){
                g ^= a[j];
                //cout << i << ' ' << j << ' ' << a[i] << ' ' << g << endl;
                --j;
            }
            if(g > a[i]){
                //cout << g << ' ' << a[i] << endl;
                mn = min(mn, i - j - 2);
            }
        }
    }
    cout << (mn == 1e9 + 7 ? -1 : mn);
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){
    return v2<T>(r, vector<T>(c, t));
}
#define F first
#define S second

int n;
vector<int> a;

void solve(){
    cin >> n;
    a = vector<int>(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }

    int ans = 1e9;

    {
        int my_ans = 0;
        int cur = 0;
        for(int i = 0; i < n-1; ++i){
            if((cur^a[i]) > a[i]){
                cur = cur^a[i];
                ++my_ans;
            }
            else{
                cur = a[i];
            }

            if(cur > a[i+1]){
                ans = min(ans, my_ans);
                break;
            }
        }
    }

    {
        int my_ans = 0;
        int cur = 0;
        for(int i = n-1; i > 0; --i){
            if((cur^a[i]) < a[i]){
                cur = cur^a[i];
                ++my_ans;
            }
            else{
                cur = a[i];
            }

            if(cur < a[i-1]){
                ans = min(ans, my_ans);
                break;
            }
        }
    }

    if(ans == 1e9){
        cout << "-1\n";
    }
    else{
        cout << ans << "\n";
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int L = 31;
const int N = 1e5;

int pnt = 0;
int mn[L * N];
int go[L * N][2];

int root;

int new_v() {
    go[pnt][0] = -1;
    go[pnt][1] = -1;
    mn[pnt] = N;
    pnt++;
    return pnt - 1;
}

void add(int x, int ind) {
    // cerr << "add " << x << endl;
    int c = root;
    for (int i = L - 1; i >= 0; i--) {
        mn[c] = min(mn[c], ind);
        if (go[c][(x >> i) & 1] == -1) {
            go[c][(x >> i) & 1] = new_v();
        }
        c = go[c][(x >> i) & 1];
    }
    mn[c] = min(mn[c], ind);
}

int solve(int a, int f) {
    // cerr << "solve " << a << ' ' << f << endl;
    int c = root;
    int ans = N;
    for (int i = L - 1; i >= 0; i--) {
        if (c == -1) {
            break;
        }
        int ab = (a >> i) & 1;
        int fb = (f >> i) & 1;
        // cerr << ab << ' ' << fb << endl;
        int nc = -1;
        for (int sb = 0; sb < 2; sb++) {
            if ((fb ^ sb) < ab) {
                if (go[c][sb] != -1) ans = min(ans, mn[go[c][sb]]);
            }
            if ((fb ^ sb) == ab) {
                nc = go[c][sb];
            }
        }
        // cerr << "nc " << nc << endl;
        c = nc;
    }
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    root = new_v();

    // {
    //     add(0, 1);
    //     cout << solve(5, 4) << endl;
    //     exit(0);
    // }

    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &t : a) {
        cin >> t;
    }
    vector<int> pf(n + 1);
    pf[n] = 0;
    for (int i = n - 1; i >= 0; i--) {
        pf[i] = pf[i + 1] ^ a[i];
    }
    int ans = n + 1;
    for (int i = n - 1; i >= 0; i--) {
        int pmn = solve(a[i], pf[i + 1]);
        if (pmn != N) ans = min(ans, pmn - (i + 1) - 1);
        add(pf[i + 1], i + 1);
    }
    {
        int c = 0;
        for (int i = 0; i < n; i++) {
            if (c > a[i]) {
                ans = min(ans, i - 1);
            }
            c ^= a[i];
        }
    }
    if (ans == n + 1) {
        cout << -1 << '\n';
    } else {
        cout << ans << '\n';
    }
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll n, a[102], pre[102];

inline ll get(ll l, ll r) { return pre[r] ^ pre[l - 1]; }
inline ll min(ll x, ll y) { return x < y ? x : y; }

int main()
{
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	if (n >= 40) cout << 1;
	else
	{
		for (ll i = 1; i <= n; i++) {
			cin >> a[i];
			pre[i] = pre[i - 1] ^ a[i];
		}
		ll ans = 1e9 + 1;
		ll mx = ans;
		for (ll i = 1; i <= n; i++)
			for (ll j = i + 1; j <= n; j++)
				for (ll k = i; k < j; k++)
					if (get(i, k) > get(k + 1, j))
						ans = min(ans, j - i - 1);
		cout << (ans == mx ? -1 : ans);
	}
}

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10, M = 4e6+10, INF = 0x3f3f3f3f;
int n, T, tot, a[N], s[N];
struct {
	int v,ch[2];
} tr[M];
void add(int &o, int d, int x, int y) {
	if (!o) o = ++tot;
	tr[o].v = y;
	if (d>=0) add(tr[o].ch[x>>d&1],d-1,x,y);
}
int query1(int o, int d, int x, int y) {
	if (!o||d<0) return -1;
	int f1 = x>>d&1, f2 = y>>d&1;
	if (f2) return query1(tr[o].ch[f1^1],d-1,x,y);
	return max(tr[tr[o].ch[f1^1]].v, query1(tr[o].ch[f1],d-1,x,y));
}
int query2(int o, int d, int x, int y) {
	if (!o||d<0) return -1;
	int f1 = x>>d&1, f2 = y>>d&1;
	if (!f2) return query2(tr[o].ch[f1],d-1,x,y);
	return max(tr[tr[o].ch[f1]].v, query2(tr[o].ch[f1^1],d-1,x,y));
}
int solve(int tp) {
	for (int i=0; i<M; ++i) tr[i].v = -1, tr[i].ch[0] = tr[i].ch[1] = 0;
	tot = T = 0;
	for (int i=1; i<=n; ++i) s[i] = s[i-1]^a[i];
	add(T,29,0,0);
	int ans = INF;
	for (int i=1; i<n; ++i) {
		if (tp==1) {
			int t = query1(T,29,s[i],a[i+1]);
			if (t!=-1) ans = min(ans, i-t-1);
		}
		else {
			int t = query2(T,29,s[i],a[i+1]);
			if (t!=-1) ans = min(ans, i-t-1);
		}
		add(T,29,s[i],i);
	}
	return ans;
}
int main() {
	scanf("%d", &n);
	for (int i=1; i<=n; ++i) scanf("%d", &a[i]);
	int ans = solve(1);
	reverse(a+1,a+1+n);
	ans = min(ans, solve(2));
	if (ans==INF) puts("-1");
	else printf("%d\n", ans);
}

#include<bits/stdc++.h>
using namespace std;

int n,Ans;

int A[100005];

inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){
       if(ch=='-')f=-1;
       ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
       x=(x<<1)+(x<<3)+ch-'0';
       ch=getchar();
    }
    return x*f;
}

inline int high(int x){
    while(x!=x&-x)
        x-=x&-x;
    return x;
}

int main(){

    n=read();

    for(register int i=1;i<=n;++i)
        A[i]=read();

    int Pos=0,sum=0;
    for(register int i=1;i<=n;++i){
        if(Pos!=high(A[i])){
            sum=1;
            Pos=high(A[i]);
        }
        else{
            ++sum;
            if(sum==3){
                printf("%d\n",1);
                return 0;
            }
        }
    }

    Ans=n;
    for(register int i=3;i<=n;++i){
        int sum=A[i-1];
        for(register int j=i-2;j;--j){
            sum^=A[j];
            if(sum>A[i]||sum<A[j-1]){
                Ans=min(Ans,i-j-1);
                break;
            }
        }
    }

    printf("%d\n",Ans==n?-1:Ans);

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define cerr cout
#define endl '\n'

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)

#define debarr(a, n) cerr << #a << " : "; for(int i = 0; i < n; i++) cerr << a[i] << " "; cerr << endl;
#define debmat(mat, row, col) cerr << #mat << " :\n"; for(int i = 0; i < row; i++){for(int j = 0; j < col; j++) cerr << mat[i][j] << " "; cerr << endl;}

typedef long long ll;
const ll MOD = 1000000007;

ll binpow(ll b, ll p){ ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % MOD; b = (b * b) % MOD; p >>= 1;}return ans;}
ll modinv(ll x){return binpow(x, MOD - 2);}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n, i, l, r, curr = 0, ans;
	cin >> n;
	vector<int> a(n), pref(n + 1, 0);
	for(i = 0; i < n; i++)
	{
		cin >> a[i];
		curr ^= a[i];
	}
	// pr(curr);
	if(curr ^ a[n - 1] > a[n - 1])
	{
		l = 0, r = n - 2;
		// ans = n - 2;
		curr ^= a[n - 1];
	}
	else if(curr ^ a[0] < a[0])
	{
		l = 1, r = n - 1;
		// ans = n - 2;
		curr ^= a[0];
	}
	else
	{
		cout << -1;
		return 0;
	}
	// pr(l, r, curr);
	while(r - l > 1)
	{
		// pr(l, r, curr);
		if((r + 1 < n && curr ^ a[l] > a[r + 1]) || curr ^ a[l] < a[l])
		{
			// ans--;
			curr ^= a[l];
			l++;
		}
		else if((l - 1 > 0 && curr ^ a[r] < a[l - 1]) || curr ^ a[r] > a[r])
		{
			// ans--;
			curr ^= a[r];
			r--;
		}
		else
			break;
	}
	cout << r - l;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <ctime>
#include <numeric>
#include <random>

#ifndef M_PI
#define M_PI 3.141592653589
#endif
#define int long long
#define uint unsigned long long
#define double long double

#ifdef TIME
#define start cin.tie(NULL); cout.tie(NULL); cout.setf(ios::fixed); cout.precision(10); ios_base::sync_with_stdio(false);int32_t START = clock()
#define finish cout << "\ntime: " << (clock() - START) / (CLOCKS_PER_SEC * 1.0); return 0
#endif

#ifndef TIME
#define start cin.tie(NULL); cout.tie(NULL); cout.setf(ios::fixed); cout.precision(10); ios_base::sync_with_stdio(false)
#define finish return 0
#endif

using namespace std;

//vector input
template<typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &i : vec) {
        cin >> i;
    }
    return is;
}

//pair output
template<typename E>
ostream &operator<<(ostream &os, pair<E, E> &t) {
    os << t.first << ' ' << t.second;
    return os;
}

//"map" pair output
template<typename E>
ostream &operator<<(ostream &os, pair<const E, E> &t) {
    os << t.first << ' ' << t.second;
    return os;
}

//vector output
template<typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
    for (T i : vec) {
        os << i << ' ';
    }
    return os;
}

//2 dimensional vector output
template<typename T>
ostream &operator<<(ostream &os, vector<vector<T> > &vec) {
    for (vector<T> i : vec) {
        os << i << '\n';
    }
    return os;
}

int32_t main() {
    start;

    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    int ans = -1;

    for (int i = 0; i < n - 3; ++i) {
        int curxor = (a[i] ^ a[i + 1] ^ a[i + 2] ^ a[i + 3]);
        if ((i != 0 && a[i - 1] > curxor) || (i != n - 4 && a[i + 4] < curxor)) {
            ans = 3;
        }
    }
    for (int i = 0; i < n - 2; ++i) {
        int curxor = (a[i] ^ a[i + 1] ^ a[i + 2]);
        if ((i != 0 && a[i - 1] > curxor) || (i != n - 3 && a[i + 3] < curxor)) {
            ans = 2;
        }
    }
    for (int i = 0; i < n - 1; ++i) {
        int curxor = (a[i] ^ a[i + 1]);
        if ((i != 0 && a[i - 1] > curxor) || (i != n - 2 && a[i + 2] < curxor)) {
            ans = 1;
        }
    }

    cout << ans << '\n';

    finish;
}

#include <bits/stdc++.h>
#define ll long long int
#define P pair
#define F first
#define S second
#define p_b push_back
#define ld long double
#define N 5000005
//#include <wadim>
ll mod = 2000000000 + 7; //4294967296; 1000000000 + 7; 998244353; 2*3*5*7*11*13*17*19*23 + 1
ll inf = (ll)(1e18);
using namespace std;

mt19937 unlucko(chrono::steady_clock::now().time_since_epoch().count());

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//using ordered_set_pair = tree<pair<ll, ll>, null_type, less<pair<ll, ll> >, rb_tree_tag, tree_order_statistics_node_update>;
//using ordered_set=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
//typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
//typedef tree<pair<ll, ll>, null_type, less_equal<pair<ll, ll> >, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset_pair;

int main() {
    iostream::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++)
        cin >> a[i];
    int ans = mod;
    for(int i=0;i<n;i++){
        int cur = 0;
        for(int j=i-1;j>=max(0, i - 100);j--){
            cur ^= a[j];
            if(cur > a[i]){
                ans = min(ans, i - j - 1);
            }
        }
    }
    if(ans == mod) cout << "-1\n";
    else cout << ans;
}

#include<bits/stdc++.h>
#define fs first
#define sc second
#define db double
#define pb push_back
#define ll long long
#define VI vector<int>
#define PII pair<int,int>
#define PQ priority_queue
#define NP next_permutation
#define ull unsigned long long
#define sz(a) (int)a.size()
#define len(a) (int)strlen(a)
#define all(a) a.begin(),a.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define F(i,j,k) for(register int i=j;i<=k;i++)
#define _M(a,b) (a##b)
#define _S(...) scanf(__VA_ARGS__)
#define _P(...) printf(__VA_ARGS__)
#define CK1(x) cout<<"["<<(x)<<"]\n";
#define CK2(x,y) cout<<"["<<(x)<<","<<(y)<<"]\n";
#define CK3(x,y,z) cout<<"["<<(x)<<","<<(y)<<","<<(z)<<"]\n";
#define CKA(a,j,k) F(cki,j,k)cout<<a[cki]<<" \n"[cki==k];
#define GKD ios::sync_with_stdio(false)
using namespace std;
const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll LINF=0x3f3f3f3f3f3f3f3f;
const int N=200020;
int n;
int a[N];
int f[N],ans=INF;
string s;
int main(){
    GKD;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        f[i]=f[i-1]^a[i];
    }
    if(n>1000){
        cout<<1;
        return 0;
    }
    a[0]=-INF;
    a[n+1]=INT32_MAX-1;
    for(int d=2;d<=n;d++){
        for(int i=1;i+d-1<n;i++){
            if(a[i+d]<(f[i-1]^f[i+d-1])){
                ans=min(ans,d-2);
            }
        }
        for(int i=2;i+d-1<=n;i++){
            if(a[i-1]>(f[i-1]^f[i+d-1])){
                ans=min(ans,d-2);
            }
        }
        if(d<4)continue;
        for(int l=1;l+d-1<=n;l++){
            int r=l+d-1;
            for(int t=l+1;t<=r-2;t++){
                int A=f[t]^f[l-1];
                int B=f[r]^f[t];
                if(A<a[l-1]||A>B||B>a[r+1]){
                    ans=min(ans,d-2);
                }
            }
        }
    }
    if(ans!=INF)cout<<ans;
    else cout<<-1;
}

#include <bits/stdc++.h>

#define pb push_back
#define int long long
#define ld long double
using namespace std;
const int M = 1000000007;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vector<int> A;
    vector<int> cnt(400);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        int l = (int) ceil(log2(x + 1));
        A.pb(x);
        cnt[l]++;
    }
    bool ok = false;
    for (auto x : cnt) {
        if (x >= 3) {
            cout << "1\n";
            exit(0);
        }
        if (x == 2) ok = true;
    }
    if (0) {
        cout << "-1\n";
    } else {
        int ans = 1e18;
        for (int l = 0; l < n; l++) {
            for (int r = l + 1; r < n; r++) {
                int num = 0;
                for (int x = l; x <= r; x++) num ^= A[x];
                if (l != 0 && A[l - 1] > num) {
                    ans = min(ans, r - l);
                } else if (r != n - 1 && A[r + 1] < num) {
                    ans = min(ans, r - l);
                }
            }
        }
        if (ans == 1e18)ans = -1;
        cout << ans << '\n';
    }
}

#include <bits/stdc++.h>

#define TASK ""
#define faster ios_base::sync_with_stdio(false) , cin.tie(NULL)
#define FOR(i , a , b) for(int i = a ; i <= b ; ++i)
#define FORD(i , a , b) for(int i = a ; i >= b ; --i)

using namespace std;

const int N = 1e5 + 5;

int t , n , p , k , a[N] , b[N];

bool check(int x){
    if(b[x + 1] > a[x + 2]) return true;
    if(a[n - x - 1] > (b[n] ^ b[n - x - 1])) return true;
    FOR(i , x + 2 , n - 1){
        int t = b[i] ^ b[i - x - 1];
        if(t < a[i - x - 1] || t > a[i + 1]) return true;
    }
    return false;
}

int main(){
//    freopen (TASK".inp" , "r" , stdin);
//    freopen (TASK".out" , "w" , stdout);
    faster;
    cin >> n;
    if(n <= 2){
        cout << -1;
        return 0;
    }
    b[0] = 0;
    FOR(i , 1 , n) {cin >> a[i]; b[i] = b[i - 1] ^ a[i];}
    int l = 1 , r = n - 1 , res = -1;
    FOR(mid , l , r)
        if(check(mid)){
            res = mid;
            break;
        }
    cout << res;
    return 0;
}

/*
* @ author: dragon_bra
* @ email: tommy514@foxmail.com
* @ data: 2020-11-29 16:40
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const double eps = 1e-5;
const int N = 2e5 + 10;

void redirect() {
    #ifdef LOCAL
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
}

int highbit(int x) {
    // leftest digit of 1
    // nearly O(1)
    union { double a; int b[2]; };
    a = x;
    return (b[1] >> 20) - 1023;
}

int n, a[N];
int h[35]; // 0-30

void solve() {
    int ans = n;
    for (int i=2; i<n; i++) {
        for (int j=1; j<=i; j++) {
            int res = 0;
            int num = i - j;
            for (int k=j; k<=i; k++) {
                res ^= a[k];
            }
            if (res > a[i+1]) {
                ans = min(ans, num);
            }
        }
    }
    if (ans == n) puts("-1");
    else printf("%d\n", ans);
}

int main() {
    redirect();

    scanf("%d", &n);
    for (int i=1; i<=n; i++) {
        scanf("%d", &a[i]);
        h[highbit(a[i])] ++;
    }

    int mx = 0;
    for (int i=0; i<=30; i++) {
        mx = max(mx, h[i]);
    }

    if (mx == 1) {
        puts("-1");
    } else if (mx == 2) {
        solve();
    } else if (mx >= 3) {
        printf("1\n");
    }

    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <cmath>
#include <queue>
#define eps 1e-7
#define M 20005
#define N 100005
#define SZ 200000002
using namespace std;
typedef long long ll;
const int inf = 1000000000;
ll mod = 1000000007LL;
ll mod2 = 998244353LL;
int n;
int a[N];
int pw[N];
int getpw(int x) {
	int pw=0;
	if (x==0) return -1;
	for (pw=0; (1LL<<pw)<=x; ++pw) {}
	return pw-1;
}
int main() {
	cin>>n;
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
	}
	for (int i = 1; i <= n; ++i) {
		pw[i] = getpw(a[i]);
	}
	int ans=-1;
	for (int i = n-1; i >= 1; --i) {
		if (pw[i]==pw[i+1]) {
			int cnt=0;
			int j = i;
			int pre=a[i+1];
			bool ok=true;
			while(j > 1) {
				int cur=a[j]^pre;
				cnt++;
				if (cur < a[j-1]) {
					break;
				} else if (getpw(cur) > pw[j-1]) {
					ok=false;
					break;
				}
				pre =cur;
				j--;
			}
			if (j > 1 && ok) {
				ans=(ans<0 ? cnt : min(ans, cnt));
			}
			int j2 = i-1;
			pre=a[i];
			cnt=0;
			while(j2>=j) {
				int cur=a[j2]^pre;
				cnt++;
				if (cur>a[i+1]) {
					break;
				}
				pre=cur;
				j2--;
			}
			if (j2>=j) {
				ans=(ans<0 ? cnt : min(ans, cnt));
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef long long int i64;

using namespace std;
using namespace std::chrono;

const i64 mod = 1'000'000'000ll + 7;
//const i64 mod = 998'244'353ll;

const i64 inf = 1'000'000'000'000'000'000ll;

const long double eps = 1e-8;

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cerr.precision(15); cerr.setf(ios::fixed);

    if (sizeof(i64) != sizeof(long long int)) {
        cerr << "i64 != long long int" << endl;
    }

    i64 n;
    cin >> n;

    vector<i64> a(n);
    for (i64 i = 0; i < n; i++) {
        cin >> a[i];
    }

    //cerr << (a[0] ^ a[1]) << " " << (a[2] ^ a[3]) << endl;

    i64 R = -1;

    for (i64 i = 1; i < n; i++) {
        i64 t = 0;
        for (i64 j = 0; j <= 30; j++) {
            i64 k = i - j - 1;
            if (k < 0) {
                break;
            }
            t ^= a[k];
            if (t > a[i]) {
                if (R == -1 || R > j) {
                    R = j;
                }
            }
        }
    }

    for (i64 i = 0; i < n - 1; i++) {
        i64 t = 0;
        for (i64 j = 0; j <= 30; j++) {
            i64 k = i + j + 1;
            if (k >= n) {
                break;
            }
            t ^= a[k];
            if (t < a[i]) {
                if (R == -1 || R > j) {
                    R = j;
                }
            }
        }
    }

    vector<i64> q;
    for (i64 i = 0; i < n - 1; i++) {
        q.push_back(a[i] ^ a[i + 1]);
    }

    vector<i64> m(n - 1);
    m.back() = q.back();
    for (i64 i = n - 3; i >= 0; i--) {
        m[i] = min(m[i + 1], q[i]);
    }

    for (i64 i = 0; i < n - 3; i++) {
        if (q[i] > m[i + 2]) {
            if (R == -1 || R > 2) {
                R = 2;
            }
        }
    }

    cout << R << endl;

    return 0;
}

#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
const int max_n = 1e5+100;
int a[max_n];
int b[max_n];
int c[max_n];
vector<int> cct[100];
int n;
int yh(int l,int r){
	return c[l]^c[r+1];
}
int get(int num){
	int ans = 0;
	while (num){
		++ans;
		num>>=1;
	}return ans;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i)scanf("%d",&a[i]);
	if (n==2){
		printf("-1\n");
		return 0;
	}
	for (int i=n;i>=1;--i)c[i] = c[i+1]^a[i];
	for (int i=1;i<n;++i){
		int tmp = a[i]^a[i+1];
		if (i!=1&&tmp<a[i-1]){
			printf("1\n");
			return 0;
		}
		if (i+2<=n&&tmp>a[i+2]){
			printf("1\n");
			return 0;
		}
	}
	for (int i=1;i<=n;++i){
		b[i]=get(a[i]);
		cct[b[i]].push_back(i);
	}
	for (int i=1;i<=32;++i){
		if (cct[i].size()>=3){
			printf("1\n");
			return 0;
		}
	}
	int res = 1e5+100;
	int f=true;
	for (int i=1;i<n;++i){
		if (!f)break;
		for (int j=1;j<=n;++j){
			int l = j;int r = j+i;
			if (r>n)break;
			int tmp = yh(l,r);
			if (l!=1&&tmp<a[l-1]){
				res = i;
				f = false;
				break;
			}
			if (r!=n&&tmp>a[r+1]){
				res=i;
				f= false;
				break;
			}
		}
	}
	if (res==1e5+100)printf("-1\n");
	else printf("%d\n",res);
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;
int A[MAXN], S[MAXN], n;
bool check(int l)
{
    for (int i = 1; i + l <= n; ++i)
        if ((S[i + l - 1] ^ S[i - 1]) > A[i + l])
            return true;
    for (int i = n; i - l >= 1; --i)
        if ((S[i] ^ S[i - l]) < A[i - l])
            return true;
    return false;
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> A[i];
    for (int i = 1; i <= n; ++i)
        S[i] = S[i - 1] ^ A[i];
    int ans = 2e9;
    for (int i = 1; i <= 100; ++i)
    {
        if (check(i))
            ans = min(ans, i);
    }
    if (ans == 2e9)
        cout << -1;
    else
        cout << ans - 1;
    return 0;
}

#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define endl '\n'

using namespace std;

const int maxn = 1e5 + 3;

int n;
int a[maxn];
void read()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	cin >> a[i];
}

void solve()
{
	if (n <= 200)
	{
		int ans = INT_MAX;
		for (int i = 2; i <= n; i++)
		{
			long long x = 0;
			for (int j = i-1; j >= 1; j--)
			{
				x ^= a[j];
				if (x > a[i])
				{
					ans = min(ans, i - j - 1);
					break;
				}
			}
		}

		for (int i = n-1; i >= 1; i--)
		{
			long long x = 0;
			for (int j = i+1; j <= n; j++)
			{
				x ^= a[j];
				if (x < a[i])
				{
					ans = min(ans, j - i - 1);
					break;
				}
			}
		}

		if (ans == INT_MAX)
		cout << -1 << endl;

		else
		cout << ans << endl;
	}

	else
	cout << 1 << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	read();
	solve();
}

#include <bits/stdc++.h>

//#define f first
//#define s second

using namespace std;

typedef long long ll;

const int N = int(1e5 + 5);
const int M = int(1e7);

struct trie {
	int l, r;
	int min_id, max_id;
	set<int> s;
	int cntl;
} t[N];

int cnt = 2;

void add(int x, int id, int v, int d = 30) {
	t[v].cntl++;
	if (d == -1) {
		t[v].s.insert(id);
		t[v].min_id = *t[v].s.begin();
		t[v].max_id = *t[v].s.rbegin();
		return;
	}
	if ((x >> d) & 1) {
		if (!t[v].r) {
			t[v].r = ++cnt;
		}
		add(x, id, t[v].r, d - 1);
	} else {
		if (!t[v].l) {
			t[v].l = ++cnt;
		}
		add(x, id, t[v].l, d - 1);
	}
	t[v].min_id = min(t[t[v].l].min_id, t[t[v].r].min_id);
	t[v].max_id = max(t[t[v].l].max_id, t[t[v].r].max_id);
}

void rem(int x, int id, int v = 2, int d = 30) {
	t[v].cntl--;
	if (d == -1) {
		t[v].s.erase(id);
		if (!t[v].s.empty()) {
			t[v].min_id = *t[v].s.begin();
		} else {
			t[v].min_id = 3e5;
		}
		return;
	}
	if ((x >> d) & 1) {
		rem(x, id, t[v].r, d - 1);
	} else {
		rem(x, id, t[v].l, d - 1);
	}
	t[v].min_id = min(t[t[v].l].min_id, t[t[v].r].min_id);
}

int get(int x, int vl = 1, int vr = 2, int d = 30) {
	if (d == -1) {
		return INT_MAX;
	}
	int cb = (x >> d) & 1, ret = INT_MAX;
	if (cb) {
		if (t[vl].l && t[t[vr].r].cntl) {
			//cout << "CB = 1 " << d << " " << t[t[vr].r].min_id << " " << t[t[vl].l].max_id << "\n";
			ret = min(ret, t[t[vr].r].min_id - t[t[vl].l].max_id - 2);
		}
	} else {
		if (t[vl].r && t[t[vr].l].cntl) {
			//cout << "CB = 0 " << d << " " << t[t[vr].l].min_id << " " << t[t[vl].r].max_id << "\n";
			ret = min(ret, t[t[vr].l].min_id - t[t[vl].r].max_id - 2);
		}
	}
	if (t[vl].l && t[vr].l) {
		ret = min(ret, get(x, t[vl].l, t[vr].l, d - 1));
	}
	if (t[vl].r && t[vr].r) {
		ret = min(ret, get(x, t[vl].r, t[vr].r, d - 1));
	}
	return ret;
}

int a[N], p[N];

void solve() {
	int n; cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		p[i] = p[i - 1] ^ a[i];
		if (i > 1) {
			add(p[i], i, 2);
		}
	}
	if (n == 2) {
		cout << "-1\n";
		return;
	}
	t[0].max_id = -3e5;
	t[0].min_id = 3e5;
	add(0, 0, 1);
	add(p[n], n + 1, 2);
	int ans = INT_MAX;
	for (int i = 1; i + 1 < n; i++) {
		ans = min(ans, get(p[i]));
		add(p[i], i, 1);
		rem(p[i + 1], i + 1);
		//cout << "------------|   " << i << " " << ans << "\n";
	}
	int xr = 0;
	for (int i = n - 1; i >= 1; i--) {
		xr ^= a[i];
		if (xr > a[n]) {
			ans = min(ans, n - i);
		}
	}
	if (ans > n - 2) {
		ans = -1;
	}
	cout << ans << "\n";
}

int main() {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0); cout.tie(0);
	int tests = 1;
	//cin >> tests;
	while (tests--) {
		solve();
	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using db = double;
using str = string; // yay python!

using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

#define tcT template<class T
#define tcTU tcT, class U
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
tcT> using PR = pair<T,T>;

// pairs
#define mp make_pair
#define f first
#define s second

// vectors
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

// loops
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const int mxN = 2e5+5;
const ll INF = 1e18; // not too close to LLONG_MAX
const ld PI = acos((ld)-1);
const int tSZ = (1 << 21);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;

// helper funcs
constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down

int add(int f, int s){ f += s; if(f >= MOD) f %= MOD; if(f < 0) f += MOD;	return f; } // add f to s and make sure it's in range
int mul(long long f, int s){ f *= s; if(f >= MOD) f %= MOD; return f;} // multiply f and s and make sure it's in range
int pw(int x, int y) { int ans = 1, ml = x; while(y) { if(y & 1) ans = mul(ans, ml); ml = mul(ml, ml);	y >>= 1; } return ans; } // number x to a power y
int inv(int x) { return pw(x, MOD - 2); }

tcT> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; } // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; }

tcTU> T fstTrue(T lo, T hi, U f) {
	hi ++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo)/2;
		f(mid) ? hi = mid : lo = mid+1;
	}
	return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
	lo --; assert(lo <= hi); // assuming f is decreasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo+1)/2;
		f(mid) ? lo = mid : hi = mid-1;
	}
	return lo;
}
tcT> void remDup(vector<T>& v) { // sort and remove duplicates
	sort(all(v)); v.erase(unique(all(v)),end(v)); }
tcTU> void erase(T& t, const U& u) { // don't erase
	auto it = t.find(u); assert(it != end(t));
	t.erase(u); } // element that doesn't exist from (multi)set

 // INPUT
#define tcTUU tcT, class ...U
tcT> void re(complex<T>& c);
tcTU> void re(pair<T,U>& p);
tcT> void re(vector<T>& v);
tcT, size_t SZ> void re(AR<T,SZ>& a);

tcT> void re(T& x) { cin >> x; }
void re(db& d) { str t; re(t); d = stod(t); }
void re(ld& d) { str t; re(t); d = stold(t); }
tcTUU> void re(T& t, U&... u) { re(t); re(u...); }

tcT> void re(complex<T>& c) { T a,b; re(a,b); c = {a,b}; }
tcTU> void re(pair<T,U>& p) { re(p.f,p.s); }
tcT> void re(vector<T>& x) { trav(a,x) re(a); }
tcT, size_t SZ> void re(AR<T,SZ>& x) { trav(a,x) re(a); }
tcT> void rv(int& n, vector<T>& x) { re(n); x.rsz(n); trav(a,x) re(a); }

// TO_STRING
#define ts to_string
str ts(char c) { return str(1,c); }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
str ts(bool b) {
	#ifdef LOCAL
		return b ? "true" : "false";
	#else
		return ts((int)b);
	#endif
}
tcT> str ts(complex<T> c) {
	stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) {
	str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
	str res = ""; F0R(i,SZ) res += char('0'+b[i]);
	return res; }
tcTU> str ts(pair<T,U> p);
tcT> str ts(T v) { // containers with begin(), end()
	#ifdef LOCAL
		bool fst = 1; str res = "{";
		for (const auto& x: v) {
			if (!fst) res += ", ";
			fst = 0; res += ts(x);
		}
		res += "}"; return res;
	#else
		bool fst = 1; str res = "";
		for (const auto& x: v) {
			if (!fst) res += " ";
			fst = 0; res += ts(x);
		}
		return res;

	#endif
}
tcTU> str ts(pair<T,U> p) {
	#ifdef LOCAL
		return "("+ts(p.f)+", "+ts(p.s)+")";
	#else
		return ts(p.f)+" "+ts(p.s);
	#endif
}

// OUTPUT
tcT> void pr(T x) { cout << ts(x); }
tcTUU> void pr(const T& t, const U&... u) {
	pr(t); pr(u...); }
void ps() { pr("\n"); } // print w/ spaces
tcTUU> void ps(const T& t, const U&... u) {
	pr(t); if (sizeof...(u)) pr(" "); ps(u...); }

 // DEBUG
void DBG() { cerr << "]" << endl; }
tcTUU> void DBG(const T& t, const U&... u) {
	cerr << ts(t); if (sizeof...(u)) cerr << ", ";
	DBG(u...); }
#ifdef LOCAL // compile with -DLOCAL, chk -> fake assert
	#define dbg(...) cerr << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
	#define chk(...) if (!(__VA_ARGS__)) cerr << "Line(" << __LINE__ << ") -> function(" \
		 << __FUNCTION__  << ") -> CHK FAILED: (" << #__VA_ARGS__ << ")" << "\n", exit(0);
#else
	#define dbg(...) 0
	#define chk(...) 0
#endif

// FILE I/O
void setIn(str s) { freopen(s.c_str(),"r",stdin); }
void setOut(str s) { freopen(s.c_str(),"w",stdout); }
void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }
void setIO(str s = "") {
	unsyncIO();
	// cin.exceptions(cin.failbit);
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

int n, a[mxN];

int solve()
{
	int tmp = 0;
	int ans = -1;
	for(int i = 1; i < n - 1; i++)
	{
		if((a[i] ^ a[i + 1]) < a[i - 1])
		{
			return 1;
		}
	}
	for(int i = 0; i < n - 1; i++)
	{
		tmp ^= a[i];
		if(tmp > a[i + 1])
		{
			ans = i;
			break;
		}
	}
	return ans;
}

int main()
{
	setIO();

	re(n);

	for(int i = 0; i < n; i++)
	{
		re(a[i]);
	}

	ps(solve());

	return 0;
	// you should actually read the stuff at the bottom
}

 /* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxv=1e2+10,maxn=1e5+10;
int a[maxn],n,id[maxn],ans=1e18,two[maxv];
int cnt[maxv];
main()
{
	two[0]=1;
	for(int i=1;i<=30;i++)two[i]=two[i-1]*2;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	for(int o=1;o<=n;o++)
	{
		for(int i=30;i>=0;i--)
		{
			if((a[o]&(two[i]))==(two[i]))
			{
				cnt[i]++;
				if(cnt[i]>2)
				{
					printf("1");
					return 0;
				}
				id[o]=i;
				break;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(i==n)continue;
		int nxt=0;
		for(int u=i+1;u<=n;u++)
		{
			int tmp=a[i],sum=0;
			nxt^=a[u];
			tmp=a[i];
			if(tmp>nxt)ans=u-i-1;
			for(int j=i-1;j>=1;j--)
			{
				tmp^=a[j];
				sum++;
				if(tmp>nxt)
				{
					ans=min(ans,sum+u-i-1);
					break;
				}
			}
//			printf("%lld %lld ",tmp,nxt);
//			printf("%lld %lld\n",ans,u);
		}
	}
	if(ans==1e18)printf("-1");
	else printf("%lld",ans);
}
/*
4
1 2 5 7
*/

#include<bits/stdc++.h>
using namespace std;
int a[100005];
int b[100005];
int vis[50];
int ans[100005];
int f(int x)
{
    int sum=0;
    while(x>0)
    {
        x=x/2;
        sum++;
    }
    return sum;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        ans[i]=(ans[i-1]^a[i]);
        b[i]=f(a[i]);
        vis[b[i]]++;
    }
    for(int i=1;i<=35;i++)
    {
        if(vis[i]>=3)
        {
            printf("-1\n");
            return 0;
        }
    }
    //printf("111\n");
    int minn=n;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<i;j++)
        {
            for(int k=i+1;k<=n;k++)
            {
                if((ans[i]^ans[j])>(ans[k]^ans[i]))
                {
                    minn=min(minn,k-j-2);
                }
            }
        }
    }
    if(minn==n) printf("-1\n");
    else printf("%d\n",minn);
    return 0;
}

#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#define pii pair<int,int>
#define fir first
#define sec second
#define mk make_pair
#define pb push_back
#define ll long long
#define N 500010
using namespace std;
inline int read()
{
	int neg=1,num=0;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')neg=-1;
	for(;isdigit(c);c=getchar())num=(num<<1)+(num<<3)+c-'0';
	return neg*num;
}
int n,m,a[N],b[N],s[N];
signed main()
{
	n=read();a[0]=-1;a[n+1]=1e9+7;
	for(int i=1;i<=n;i++)a[i]=read();
	m=n;
	for(int i=30;i>=0;i--)
		for(int j=1;j<=m;j++)
		{
			if(a[j]>>i&1)
			{
				if(m-j+1>=3)cout<<1<<endl,exit(0);
				m=j-1;
				break;
			}
		}
	if(n<=100)
	{
		int ans=101;
		for(int i=1;i<=n;i++)
			for(int j=i+1;j<n;j++)
			{
				int x=0;
				for(int k=i;k<=j;k++)x^=a[k];
				if(x<a[i-1] || x>a[j+1])ans=min(ans,j-i);
			}
		if(ans==101)cout<<-1<<endl;
		else cout<<ans<<endl;
		return 0;
	}
	cout<<-1<<endl;
	return 0;
}

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define print(x) cout << #x <<" = " << x <<"\n"
#define pprint(x) cout << #x <<" = (" << x.first <<" , " << x.second <<" )\n"
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define ceil(a, b) ((a + b - 1) / b)
#define all(x) x.begin(), x.end()

#define MAXN 1000005
#define MOD 1000000007
#define INF 100000000000000000
#define eps (1e-9)

#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

using namespace std;
int n,cur;
vector<vector<int>> pre;
int bs(int id, int d) {
	int L = 0, R = id;
	while(R - L > 1) {
		int mid = (L + R) / 2;
		if(pre[d][id - 1] - pre[d][mid - 1] > 0) L = mid;
		else R = mid;
	}
//	print(id), print(L);
	return L;
}
int solve() {
	bool cs1 = 0;
	rep(i, 1, n) {
		int top = 32;
		while(pre[top][i] - pre[top][i-1] != 1) top--;
		if(pre[top][i] > 2) {
			cs1 = 1;
			break;
		}
	}
	if(cs1) return 1;
	int ans = INF, cnt = 0, cur, id;
	rep(i, 1, n) {
		int top = 32;
		while(pre[top][i] - pre[top][i-1] != 1) top--;
		if(pre[top][i] == 2) {
			cnt = 0, cur = i - 1;
//			print(i);
			rrep(j, 0, top-1) {
				if(!((pre[j][i - 1] - pre[j][cur - 1]) & 1))
					id = bs(cur, j);
				else id = cur;
//				print(j);print(id);
//				pprint(pii(pre[j][i], pre[j][i-1]));
				if(pre[j][i] - pre[j][i-1] == 0) cnt = max(cnt, id);
				else cur = id;
			}

			if(cnt != 0) ans = min(i - 1 - cnt, ans);
		}
	}

	if(ans == INF) return -1;
	return ans;

}
signed main() {
//	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n, pre.assign(33, vector<int>(n + 1, 0));
	rep(i, 1, n) {
		cin >> cur;
		rep(j, 0, 32) {
			pre[j][i] = pre[j][i - 1] + ((cur >> j) & 1);
		}
	}
	cout << solve() <<"\n";
	return 0;
}

            #define Oo ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1.0)
typedef  long long ll;
int a[100005];
int sum[100005];
int main()
{
      Oo
      int n;cin>>n;
      for (int i=1; i<=n; i++)cin>>a[i];
      int flag=0;
      for (int i=1; i<n; i++)
      {
            if (i>1&&(a[i]^a[i+1]<a[i-1]))
            {
                  flag=1;break;
            }
            if (i<n-1&&(a[i]^a[i+1])>a[i+2])
            {
                  flag=1;break;
            }
      }
      if (flag)cout<<1<<endl;
      else
      {
            sum[0]=0;
            for(int i=1; i<=n; i++)
            {
                  sum[i]=sum[i-1]^a[i];
            }
            int ans = INT_MAX;
            for (int i=1; i<=n; i++)
                  for (int j=i; j>=1; j--)
                  for (int k=i+1; k<=n; k++)
                  if (sum[i]^sum[j-1]>sum[k]^sum[i])
                  ans = min(ans, k-j-1);
            cout << (ans==INT_MAX?-1:ans) << endl;
      }
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100005];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%d",&a[i]);
    for(int i=1;i<n-1;++i)
    {
        if((a[i+1]^a[i+2])<a[i])
        {
            puts("1");
            return 0;
        }
    }
    int ans=100;
    for(int i=3;i<=n;++i)
    {
        int tmp=0;
        int now=a[i-1];
        for(int j=i-2;j>=1;--j)
        {
            //cout<<now<<endl;
            now^=a[j];
            tmp++;
            if(now>a[i])
            {
                ans=min(ans,tmp);
                break;
            }
        }
        //if(i==n)break;
        int tt=a[i-1]^a[i];
        if(i<n&&tt>a[i+1])
        {
            ans=1;
            break;
        }
        tmp=1;
        now=a[i-2];
        for(int j=i-3;j>=1;--j)
        {
            now^=a[j];
            //cout<<now<<" "<<tt<<endl;
            tmp++;
            if(now==tt&&j>1)
            {
                tmp++;
                ans=min(ans,tmp);
                break;
            }
            if(i<n&&now>tt)
            {
                ans=min(ans,tmp);
                break;
            }
        }
    }
    if(ans==100)ans=-1;
    printf("%d\n",ans);
    return 0;
}

#include <iostream>
#include <cstdio>
#define maxn 100010
using namespace std;

int n, a[maxn], s[maxn];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    if (n <= 60) {
        int ans = n;
        for (int i = 1; i <= n; ++i) s[i] = s[i - 1] ^ a[i];
        for (int i = 2; i < n; ++i)
            for (int j = 1; j <= i; ++j)
                for (int k = i + 1; k <= n; ++k)
                    if ((s[i] ^ s[j - 1]) > (s[k] ^ s[i]))
                        ans = min(ans, k - j - 1);
        ans == n ? cout << "-1\n" : cout << ans << "\n";
    }
    else cout << "1\n";
    return 0;
}

/**
 * @author yuzining
 * @date 2020/11/29 15:46
 */

#ifdef local
#include "D:\VSCODE\local.hpp"
#else
#include<bits/stdc++.h>
using namespace std;
#define debug(...) do { } while(0)
void Main();
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
  return 0;
}
#endif

int a[100005];
int b[100005];

void Main() {
  int n; cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = b[i - 1] ^ a[i];
  }
  a[n + 1] = INT_MAX;
  if (n > 1000) {
    cout << 1 << '\n';
    return;
  }
  int ans = INT_MAX;
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if ((b[j] ^ b[i - 1]) > a[j + 1]) {
        ans = min(j - i, ans);
      }
      if ((b[j] ^ b[i - 1]) < a[i - 1]) {
        ans = min(j - i, ans);
      }
    }
  }
  if (ans == INT_MAX) {
    cout << -1 << '\n';
  } else {
    cout << ans << '\n';
  }
}

#include <bits/stdc++.h>

#define TASK ""
#define faster ios_base::sync_with_stdio(false) , cin.tie(NULL)
#define FOR(i , a , b) for(int i = a ; i <= b ; ++i)
#define FORD(i , a , b) for(int i = a ; i >= b ; --i)

using namespace std;

const int N = 1e5 + 5;

int t , n , p , k , a[N] , b[N];

bool check(int x){
    if(b[x + 1] > a[x + 2]) return true;
    if(a[n - x - 1] > (b[n] ^ b[n - x - 1])) return true;
    FOR(i , x + 2 , n - 1){
        int t = b[i] ^ b[i - x - 1];
        if(t < a[i - x - 1] || t > a[i + 1]) return true;
    }
    return false;
}

int main(){
//    freopen (TASK".inp" , "r" , stdin);
//    freopen (TASK".out" , "w" , stdout);
    faster;
    cin >> n;
    if(n <= 2){
        cout << -1;
        return 0;
    }
    b[0] = 0;
    FOR(i , 1 , n) {cin >> a[i]; b[i] = b[i - 1] ^ a[i];}
    int l = 1 , r = n - 2 , res = -1;
    FOR(mid , l , r)
        if(check(mid)){
            res = mid;
            break;
        }
    cout << res;
    return 0;
}

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#include <iomanip>
#include <float.h>
#define _USE_MATH_DEFINES
#include <math.h>

#define ll long long

#define FOR(i,a,b)        for(ll i=(a);i<(b);i++)
#define REP(i,n)        FOR(i,0,n)
#define SORT(v)            sort((v).begin(),(v).end())
#define UN(v)            SORT(v),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define CL(a,b)            memset(a,b,sizeof a)
#define pb                push_back

#ifndef M_PI
    #define M_PI 3.14159265358979323846
#endif

using namespace std;

//#define N 1000009
ll denom = 998244353;
ll powmod(ll a,ll b) {ll res=1;a%=denom; for(;b;b>>=1){if(b&1)res=res*a%denom;a=a*a%denom;}return res;}

ll solve(vector<ll>& a) {
    ll result = INT_MAX;
    ll n = a.size();

    vector<ll> dp(n+1, 0); REP(i, n) dp[i+1] = a[i]^dp[i];
    REP(i, n) {
        REP(left, i) {
            FOR(right, i+1, n) {
                ll l = dp[i+1]^dp[left];
                ll r = dp[right+1]^dp[i+1];
                if (l > r) {
                    result = min(result, right-left-1);
                }
            }
        }
    }
    return result;
}

int main(int argc, const char * argv[])
{
    ios_base::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(n); REP(i, n) cin >> a[i];
    vector<vector<ll>> v(32);
    REP(i, n) {
        for (ll j = 31; j >= 0; j--) {
            if ((1 << j) & a[i]) {
                v[j].push_back(a[i]);
                break;
            }
        }
    }
    REP(i, 32) {
        if (v[i].size() > 2) {
            cout << 1 << endl;
            return 0;
        }
    }
    bool allOne = true;
    REP(i, 32) {
        if (v[i].size() > 1) {
            allOne = false;
            break;
        }
    }
    if (allOne) {
        cout << -1 << endl;
        return 0;
    }
    ll result = solve(a);
    cout << (result == INT_MAX ? -1 : result) << endl;
    return 0;
}

#include <iostream>
#include <fstream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <algorithm>
#include <stack>
#include <string>
#include <math.h>
#include <cmath>
using namespace std;
typedef long long int ll;
int log2s(int fdsa) {
    double calc = fdsa;
    return (int)log2(calc);
}
int main() {
    //GOOD LUCK
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i ++) {
        cin >> a[i];
    }
    bool fdsa = false;
    bool eh = false;
    for (int i = 1; i < n-1; i ++) {
        //cout << log2s(a[i-1]) << " "<<  log2s(a[i]) << " " << log2s(a[i+1]) << endl;
        // if ((int)double(a[i-1]) == (int)double(a[i]) || (int)double(a[i]) == (int)double(a[i+1])) {
        //     eh = true;
        // }
        if ((int)double(a[i-1]) == (int)double(a[i]) && (int)double(a[i]) == (int)double(a[i+1])) {
            cout << 1 << endl;
            return 0;
        }
    }
    int xorl[n][n];
    for (int i = 0; i < n; i ++) {
        for (int j = i; j < n; j ++) {
            xorl[i][j] = a[i];
            for (int k = i+1; k <= j; k ++) {
                xorl[i][j] = xorl[i][j] ^ a[k];
            }
            //cout << xorl[i][j] << " ";
        }
        //cout << endl;
    }
    // if (!eh) {
        // cout << -1 << endl;
        // return 0;
    // }
    int ans = 1000000000;
    for (int i = 0; i < n; i ++) {
        for (int j = i+1; j < n; j ++) {
            for (int k = j+1; k < n; k ++) {
                if (xorl[i][j] > xorl[j+1][k]) {
                    ans = min(ans, j-i+k-j-1);
                    //cout << i << " " << j << " " << k << endl << endl;
                }
            }
        }
    }
    if (ans != 1000000000) {
        cout << ans << endl;
    }
    else {
        cout << -1 << endl;
    }
}