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

const int MAXN = 200 ;
const int MAXM = 50 * 1000 ;

#define pb push_back
#define X first
#define Y second

typedef long long ll ;
typedef pair <ll,ll> pii ;
typedef pair <pii,pii> pipi ;

const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000  ;

int N , M ;
int G , S ;

// vector <int> d[MAXN] ;
// vector <int> num[MAXN] ;

int parent[MAXN] ;
int siz[MAXN] ;
ll minSilver[MAXN] ;
ll mSilver = INF ;

pipi e[MAXM] ;
bool cmp (pipi a , pipi b) {
    return a.Y.X < b.Y.X ;
}

struct comp {
    bool operator () (int a , int b) {
        if (e[a].Y.Y != e[b].Y.Y)
            return e[a].Y.Y < e[b].Y.Y ;
        return a < b ;
    }
};

set <int,comp> v[MAXN] ;

ll findpath (ll a) {
    if (a == parent[a]) return a ;
    ll b = findpath (parent[a]) ;
    parent[a] = b ;
    return b ;
}

bool is[MAXN] ;
int dfs (ll a , ll b , ll c) {
    if (is[a]) return -2;
    if (a == b) return -1 ;
    is[a] = true ;
    int ans = -2 , got = -2 ;
    for (set<int,comp>::iterator it = v[a].begin() ; it != v[a].end() ; ++it) {
        int f = *it ;
        int nei = e[f].X.X^e[f].X.Y^a ;
        int DFS = dfs(nei,b,c) ;
        if (DFS == -1) {
            ans = e[f].Y.Y ;
            got = f ;
        }
        if (DFS >= 0) {
            if (e[DFS].Y.Y > ans) {
                ans = e[DFS].Y.Y ;
                got = DFS ;
            }
            if (e[f].Y.Y > ans) {
                ans = e[f].Y.Y ;
                got = f ;
            }
        }
    }
    return got ;
}

void Add (ll a , ll b) {
    //d[a].pb (b) ;
    //num[a].pb (c) ;
    v[a].insert (b) ;
}

void Join (ll a , ll b , ll c, ll d) {
    if (a == b) return ;
    ll ga = findpath(a) ;
    ll gb = findpath(b) ;
    //  cerr << ga << " : " << gb << endl ;
    if (ga == gb) {
        memset (is,false,sizeof(is)) ;
        int ret = dfs (a,b,c) ;
        if (ret >= 0 && e[ret].Y.Y > c) {
//             cerr << a << " " << b << " " << c << " " << d << " : ret = " << ret << endl ;
            v[e[ret].X.X].erase (ret) ;
            v[e[ret].X.Y].erase (ret) ;
            Add (a,d) ;
            Add (b,d) ;
//             cerr << v[a].size() << " , " << v[b].size() << endl ;
            minSilver[ga] += c-e[ret].Y.Y ;
        }
        if (siz[ga] == N)
            mSilver = min (mSilver , minSilver[ga]) ;
        return ;
    }
    if (siz[ga] < siz[gb]) swap(ga,gb) ;
    parent[gb] = ga ;
    siz[ga] += siz[gb] ;
    Add(a,d) ;
    Add(b,d) ;
    minSilver[ga] = max(minSilver[ga] , max(c,minSilver[gb])) ;
//       cerr << "minSilver[" << ga << "] = " << minSilver[ga] << endl ;
//       cerr << "siz[" << ga << "] = " << siz[ga] << endl ;
    if (siz[ga] == N)
        mSilver = minSilver[ga] ;
}

int main() {
    cin >> N >> M >> G >> S ;
    for (int i = 0 ; i < M ; ++i) {
        cin >> e[i].X.X >> e[i].X.Y >> e[i].Y.X >> e[i].Y.Y ; --e[i].X.X , --e[i].X.Y ;
    }
    sort (e,e+M,cmp) ;
    for (int i = 0 ; i < N ; ++i) {
        parent[i] = i ;
        siz[i] = 1 ;
    }
    ll BestAns = INF ;
    for (int i = 0 ; i < M ; ++i) {
//           cerr << e[i].X.X << " " << e[i].X.Y << "   : " << e[i].Y.X << " , " << e[i].Y.Y << endl ;
        Join (e[i].X.X , e[i].X.Y , e[i].Y.Y , i) ;
//           cerr << endl << "-------------------------------------------------------------------------------------------------------------------" << endl << endl << endl;
        BestAns = min (BestAns,e[i].Y.X*G+mSilver*S) ;
    }
    cout << ((BestAns<INF)?BestAns:-1) << endl ;
    return 0 ;
}


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

#define pb push_back
#define X first
#define Y second

typedef long long ll ;
typedef pair <ll,ll> pii ;
typedef pair <pii,pii> pipi ;

const ll MAXN = 200 ;
const ll MAXM = 50 * 1000 ;
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 10  ;

ll N , M ;
ll G , S ;

// vector <ll> d[MAXN] ;
// vector <ll> num[MAXN] ;

ll parent[MAXN] ;
ll siz[MAXN] ;
multiset <ll> minSilver[MAXN] ;
ll mSilver = INF ;

pipi e[MAXM] ;
bool cmp (pipi a , pipi b) {
    return a.Y.X < b.Y.X ;
}

struct comp {
    bool operator () (ll a , ll b) {
        if (e[a].Y.Y != e[b].Y.Y)
            return e[a].Y.Y < e[b].Y.Y ;
        return a < b ;
    }
};

set <ll,comp> v[MAXN] ;

ll findpath (ll a) {
    if (a == parent[a]) return a ;
    ll b = findpath (parent[a]) ;
    parent[a] = b ;
    return b ;
}

bool is[MAXN] ;
ll dfs (ll a , ll b , ll c) {
    if (is[a]) return -2;
    if (a == b) return -1 ;
    is[a] = true ;
    ll ans = -2 , got = -2 ;
    for (set<ll,comp>::iterator it = v[a].begin() ; it != v[a].end() ; ++it) {
        ll f = *it ;
        ll nei = e[f].X.X^e[f].X.Y^a ;
        ll DFS = dfs(nei,b,c) ;
        if (DFS == -1) {
            ans = e[f].Y.Y ;
            got = f ;
        }
        if (DFS >= 0) {
            if (e[DFS].Y.Y > ans) {
                ans = e[DFS].Y.Y ;
                got = DFS ;
            }
            if (e[f].Y.Y > ans) {
                ans = e[f].Y.Y ;
                got = f ;
            }
        }
    }
    return got ;
}

void Add (ll a , ll b) {
    //d[a].pb (b) ;
    //num[a].pb (c) ;
    v[a].insert (b) ;
}

ll Last (multiset <ll> & a) {
    multiset <ll>::iterator it = a.end() ;
    --it ;
    return *it ;
}

void Join (ll a , ll b , ll c, ll d) {
    if (a == b) return ;
    ll ga = findpath(a) ;
    ll gb = findpath(b) ;
//       cerr << ga << " : " << gb << endl ;
    if (ga == gb) {
        memset (is,false,sizeof(is)) ;
        ll ret = dfs (a,b,c) ;
        if (ret >= 0 && e[ret].Y.Y > c) {
//             cerr << a << " " << b << " " << c << " " << d << " : ret = " << ret << endl ;
//             cerr << "e[ret] : " << e[ret].Y.X << " , " << e[ret].Y.Y << endl ;
            v[e[ret].X.X].erase (ret) ;
            v[e[ret].X.Y].erase (ret) ;
            Add (a,d) ;
            Add (b,d) ;
//             cerr << v[a].size() << " , " << v[b].size() << endl ;
//             for (multiset <ll>::iterator it = minSilver[ga].begin() ; it != minSilver[ga].end() ; ++it) {
//                 cerr << *it << " . " ;
//             }
//             cerr << endl ;
            minSilver[ga].erase (minSilver[ga].find(e[ret].Y.Y)) ;
//             cerr << v[a].size() << " , " << v[b].size() << endl ;
//             for (multiset <ll>::iterator it = minSilver[ga].begin() ; it != minSilver[ga].end() ; ++it) {
//                 cerr << *it << " . " ;
//             }
//             cerr << endl ;
            minSilver[ga].insert (c) ;
//             cerr <<"minSilver[ga] = " <<  Last(minSilver[ga]) << endl ;
        }
        if (siz[ga] == N) {
            mSilver = min (mSilver , Last(minSilver[ga])) ;
        }
        return ;
    }
    if (siz[ga] < siz[gb]) swap(ga,gb) ;
    parent[gb] = ga ;
    siz[ga] += siz[gb] ;
    Add(a,d) ;
    Add(b,d) ;
    for (multiset<ll>::iterator it = minSilver[gb].begin() ; it != minSilver[gb].end() ; ++it) {
        minSilver[ga].insert (*it) ;
    }
    minSilver[ga].insert (c) ;
    //minSilver[ga] = max(minSilver[ga] , max(c,minSilver[gb])) ;
//     cerr << "minSilver[" << ga << "] = " << Last(minSilver[ga]) << endl ;
//     cerr << "siz[" << ga << "] = " << siz[ga] << endl ;
    if (siz[ga] == N) {
        mSilver = Last(minSilver[ga]) ;
    }
}

int main() {
    cin >> N >> M >> G >> S ;
    for (ll i = 0 ; i < M ; ++i) {
        cin >> e[i].X.X >> e[i].X.Y >> e[i].Y.X >> e[i].Y.Y ; --e[i].X.X , --e[i].X.Y ;
    }
    sort (e,e+M,cmp) ;
    for (ll i = 0 ; i < N ; ++i) {
        parent[i] = i ;
        siz[i] = 1 ;
    }
    ll BestAns = INF ;
    for (ll i = 0 ; i < M ; ++i) {
//         cerr << e[i].X.X << " " << e[i].X.Y << "   : " << e[i].Y.X << " , " << e[i].Y.Y << endl ;
        Join (e[i].X.X , e[i].X.Y , e[i].Y.Y , i) ;
//         cerr << endl ;
//         cerr << e[i].Y.X*G << " + " << mSilver*S << endl ;
//         cerr << "-------------------------------------------------------------------------" << endl << endl ;
        BestAns = min (BestAns,e[i].Y.X*G+mSilver*S) ;
    }
    cout << ((BestAns<INF)?BestAns:-1) << endl ;
    return 0 ;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<utility>
#include<cstdlib>
#include<ctime>
#include<cctype>
#include<string>
using namespace std;
#define mp make_pair
#define pb push_back
#define pf push_front
#define X first
#define Y second
#define lch(x) ((x)<<1)
#define rch(x) (((x)<<1)^1)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int N=205,M=5e4+7;
const ll inf=1e11+7;

int n,m;
ll vg,vs;

struct edge{
	int from,to,id;
	ll g,s;
}a[M],b[M];

struct Node{
	int par[N],sz;

	Node(){
		sz=0;
		memset(par,-1,sizeof(par));
	}

	int find(int x){
		return par[x]<0?x:par[x]=find(par[x]);
	}

	void join(int x,int y){
		x=find(x),y=find(y);
		if(x==y) return;
		if(par[x]<par[y]){
			par[x]+=par[y];
			par[y]=x;
		} else{
			par[y]+=par[x];
			par[x]=y;
		}
		++sz;
	}

	void merge(const Node &b){
		for(int i=1;i<=::n;i++) join(i,b.par[i]);
	}

}node[M<<2],tmp,temp;

void ins(int t,int l,int r,int p,edge &e){
	node[t].join(e.from,e.to);
	if(l==r) return;
	int mid=l+r>>1;
	if(p<=mid) ins(lch(t),l,mid,p,e);
	else ins(rch(t),mid+1,r,p,e);
}

ll query(int t,int l,int r){
	if(l==r) return a[t].s;
	int mid=l+r>>1;
	temp=tmp;
	temp.merge(node[lch(t)]);
	if(temp.sz==1){
		return query(lch(t),l,mid);
	}else{
		tmp=temp;
		return query(rch(t),mid+1,r);
	}
}

bool cmp_g(const edge &a,const edge &b){
	if(a.g!=b.g) return a.g<b.g;
	return a.s<b.s;
}

bool cmp_s(const edge &a,const edge &b){
	if(a.s!=b.s) return a.s<b.s;
	return a.g<b.g;
}

int main(){
	scanf("%d%d%I64d%I64d",&n,&m,&vg,&vs);
	for(int i=1;i<=m;i++){
		scanf("%d%d%I64d%I64d",&a[i].from,&a[i].to,&a[i].g,&a[i].s);
		a[i].id=i;
		b[i]=a[i];
	}
	sort(a+1,a+m+1,cmp_s);
	for(int i=1;i<=m;i++) b[a[i].id].id=i;
	sort(b+1,b+m+1,cmp_g);

//	for(int i=1;i<=m;i++) printf("(%d->%d %d %d)",a[i].from,a[i].to,a[i].g,a[i].s);puts("");
//	for(int i=1;i<=m;i++) printf("(%d->%d %d %d %d)",b[i].from,b[i].to,b[i].g,b[i].s,b[i].id);puts("");

	ll ans=-1;
	for(int i=1;i<=m;i++){
		ins(1,1,m,b[i].id,b[i]);
	//	printf("%d\n",node[1].sz);
	//	for(int j=1;j<=n;j++) printf("%d ",node[1].par[j]);puts("");
		if(node[1].sz!=n-1) continue;
		tmp=Node();
		ll need=query(1,1,m);
		ll sum=b[i].g*vg+need*vs;
		if(ans==-1) ans=sum;else ans=min(ans,sum);
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define pb push_back
typedef long long ll;

const int N=205,M=50005;
const ll inf=1e18+7;

struct edge{
	int u,v;
	ll g,s;
}e[M];
int n,m;
ll vg,vs;
int par[N];
vector<int> used(0),newv(0);

bool cmpg(const edge &a,const edge &b){
	if(a.g!=b.g) return a.g<b.g;
	return a.s<b.s;
}

bool cmps(const int a,const int b){
	if(e[a].s!=e[b].s) return e[a].s<e[b].s;
	return e[a].g<e[b].g;
}

int find(int x){
	return par[x]<0?x:par[x]=find(par[x]);
}

void join(int x,int y){
	if(x==y) return;
	if(par[x]<par[y]){
		par[x]+=par[y];
		par[y]=x;
	}else{
		par[y]+=par[x];
		par[x]=y;
	}
}

int main(){
	scanf("%d%d%I64d%I64d",&n,&m,&vg,&vs);
	for(int i=1;i<=m;i++) scanf("%d%d%I64d%I64d",&e[i].u,&e[i].v,&e[i].g,&e[i].s);
	sort(e+1,e+1+m,cmpg);
	ll ans=inf;
	for(int i=1;i<=m;i++){
		newv=used;
		used.clear();
		newv.pb(i);
		sort(newv.begin(),newv.end(),cmps);
		memset(par,-1,sizeof(par));
		ll mx=0;
		for(int j=0;j<newv.size();j++){
			int v=newv[j],x=find(e[v].u),y=find(e[v].v);
			if(x==y) continue;
			mx=max(e[v].s,mx);
			join(x,y);
			used.pb(v);
		}
		if(used.size()==n-1){
			ans=min(ans,e[i].g*vg+mx*vs);
		}
	}
	if(ans==inf) puts("-1");
	else printf("%I64d\n",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define pb push_back
typedef long long ll;

const int N=205,M=50005;

struct edge{
	int from,to,nxt;
	ll g,s;
	bool can;

	edge():from(0),to(0),nxt(0),g(0),s(0),can(true){}

	bool operator <(const edge &b)const{
		if(g!=b.g) return g<b.g;
		return s<b.s;
	}

}e[M<<1];
int n,m,par[N],head[N];
vector<int> used;
ll vg,vs;

int find(int x){
	return par[x]<0?x:par[x]=find(par[x]);
}

void join(int x,int y){
	if(x==y) return;
	if(par[x]<par[y]){
		par[x]+=par[y];
		par[y]=x;
	}else{
		par[y]+=par[x];
		par[x]=y;
	}
}

void addedge(int u,int p){
	e[p].nxt=head[u],head[u]=p;
}

int findmax(int u,int parent,int pos){
	for(int p=head[u];p;p=e[p].nxt){
		if(!e[p].can||e[p].to==parent) continue;
		int v=e[p].to;
		if(v==pos){
			return p;
		}else{
			int p2=findmax(v,u,pos);
			if(p2==-1) continue;
			if(e[p2].s<e[p].s) return p;else return p2;
		}
	}
	return -1;
}

int main(){
	scanf("%d%d%I64d%I64d",&n,&m,&vg,&vs);
	for(int i=1;i<=m;i++){
		scanf("%d%d%I64d%I64d",&e[i].from,&e[i].to,&e[i].g,&e[i].s);
		e[i+m]=e[i];
		swap(e[i+m].from,e[i+m].to);
	}
	sort(e+1,e+m+1);
	memset(par,-1,sizeof(par));
	int num=0;
	ll need=0,ans=-1;
	for(int i=1;i<=m;i++){
	//	printf("%dbegin\n",i);
		int x=find(e[i].from),y=find(e[i].to);
		if(x==y){
			int p=findmax(e[i].from,-1,e[i].to);
		//	printf("p=(%d %d)\n",e[p].from,e[p].to);
			if(e[p].s<=e[i].s) continue;
			if(p>m) p-=m;
			e[p].can=e[p+m].can=false;
			for(vector<int>::iterator ite=used.begin();ite!=used.end();++ite) if((*ite)==p){
				used.erase(ite);
				break;
			}
			addedge(e[i].from,i);
			addedge(e[i].to,i+m);
			used.pb(i);
		}else{
			join(x,y);
			addedge(e[i].from,i);
			addedge(e[i].to,i+m);
			++num;
			used.pb(i);
		}
	//	for(int j=0;j<used.size();j++) printf("(%d %d) ",e[used[j]].from,e[used[j]].to);puts("");
		if(num==n-1){
			need=0;
			for(int j=0;j<used.size();j++) need=max(need,e[used[j]].s);
			ll cost=e[i].g*vg+need*vs;
			if(ans==-1) ans=cost;else ans=min(ans,cost);
		}
	//	printf("end%d %d\n",need,ans);
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define pb push_back

const int N=205,M=50005;
const int inf=1e9+7;

struct edge{
	int u,v,g,s;
}e[M];
int n,m,vg,vs;
int par[N];
vector<int> used(0),newv(0);

bool cmpg(const edge &a,const edge &b){
	if(a.g!=b.g) return a.g<b.g;
	return a.s<b.s;
}

bool cmps(const int a,const int b){
	if(e[a].s!=e[b].s) return e[a].s<e[b].s;
	return e[a].g<e[b].g;
}

int find(int x){
	return par[x]<0?x:par[x]=find(par[x]);
}

void join(int x,int y){
	if(x==y) return;
	if(par[x]<par[y]){
		par[x]+=par[y];
		par[y]=x;
	}else{
		par[y]+=par[x];
		par[x]=y;
	}
}

int main(){
	scanf("%d%d%d%d",&n,&m,&vg,&vs);
	for(int i=1;i<=m;i++) scanf("%d%d%d%d",&e[i].u,&e[i].v,&e[i].g,&e[i].s);
	sort(e+1,e+1+m,cmpg);
	int ans=inf;
	for(int i=1;i<=m;i++){
		newv=used;
		used.clear();
		newv.pb(i);
		sort(newv.begin(),newv.end(),cmps);
		memset(par,-1,sizeof(par));
		int mx=0;
		for(int j=0;j<newv.size();j++){
			int v=newv[j],x=find(e[v].u),y=find(e[v].v);
			if(x==y) continue;
			mx=max(e[v].s,mx);
			join(x,y);
			used.pb(v);
		}
		if(used.size()==n-1){
			ans=min(ans,e[i].g*vg+mx*vs);
		}
	}
	printf("%d\n",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define pb push_back
typedef long long ll;

const int N=205,M=50005;

struct edge{
	int u,v;
	ll g,s;
}e[M];
int n,m;
ll vg,vs;
int par[N];
vector<int> used(0),newv(0);

bool cmpg(const edge &a,const edge &b){
	if(a.g!=b.g) return a.g<b.g;
	return a.s<b.s;
}

bool cmps(const int a,const int b){
	if(e[a].s!=e[b].s) return e[a].s<e[b].s;
	return e[a].g<e[b].g;
}

int find(int x){
	return par[x]<0?x:par[x]=find(par[x]);
}

void join(int x,int y){
	if(x==y) return;
	if(par[x]<par[y]){
		par[x]+=par[y];
		par[y]=x;
	}else{
		par[y]+=par[x];
		par[x]=y;
	}
}

int main(){
	scanf("%d%d%I64d%I64d",&n,&m,&vg,&vs);
	for(int i=1;i<=m;i++) scanf("%d%d%I64d%I64d",&e[i].u,&e[i].v,&e[i].g,&e[i].s);
	sort(e+1,e+1+m,cmpg);
	ll ans=-1;
	for(int i=1;i<=m;i++){
		newv=used;
		newv.pb(i);
		sort(newv.begin(),newv.end(),cmps);
		memset(par,-1,sizeof(par));
		ll mx=0;
		used.clear();
		for(int j=0;j<newv.size();j++){
			int v=newv[j],x=find(e[v].u),y=find(e[v].v);
			if(x==y) continue;
			mx=max(e[v].s,mx);
			join(x,y);
			used.pb(v);
		}
		if(used.size()==n-1){
			if(ans==-1) ans=e[i].g*vg+mx*vs;else ans=min(ans,e[i].g*vg+mx*vs);
		}
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<utility>
#include<cstdlib>
#include<ctime>
#include<cctype>
#include<string>
using namespace std;
#define mp make_pair
#define pb push_back
#define pf push_front
#define X first
#define Y second
#define lch(x) ((x)<<1)
#define rch(x) (((x)<<1)^1)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int N=205,M=5e4+7;
const ll inf=1e11+7;

int n,m;
ll vg,vs;

struct edge{
	int from,to,id;
	ll g,s;
}a[M],b[M];

struct Node{
	int par[N],sz;

	Node(){
		sz=0;
		memset(par,-1,sizeof(par));
	}

	int find(int x){
		return par[x]<0?x:par[x]=find(par[x]);
	}

	void join(int x,int y){
		x=find(x),y=find(y);
		if(x==y) return;
		if(par[x]<par[y]){
			par[x]+=par[y];
			par[y]=x;
		} else{
			par[y]+=par[x];
			par[x]=y;
		}
		++sz;
	}

	void merge(const Node &b){
		for(int i=1;i<=::n;i++) join(i,b.par[i]);
	}

}node[M<<2],tmp,temp;

void ins(int t,int l,int r,int p,edge &e){
	node[t].join(e.from,e.to);
	if(l==r) return;
	int mid=l+r>>1;
	if(p<=mid) ins(lch(t),l,mid,p,e);
	else ins(rch(t),mid+1,r,p,e);
}

ll query(int t,int l,int r){
	if(l==r) return a[t].s;
	int mid=l+r>>1;
	temp=tmp;
	temp.merge(node[lch(t)]);
	if(temp.sz==n-1){
		return query(lch(t),l,mid);
	}else{
		tmp=temp;
		return query(rch(t),mid+1,r);
	}
}

bool cmp_g(const edge &a,const edge &b){
	if(a.g!=b.g) return a.g<b.g;
	return a.s<b.s;
}

bool cmp_s(const edge &a,const edge &b){
	if(a.s!=b.s) return a.s<b.s;
	return a.g<b.g;
}

int main(){
	scanf("%d%d%I64d%I64d",&n,&m,&vg,&vs);
	for(int i=1;i<=m;i++){
		scanf("%d%d%I64d%I64d",&a[i].from,&a[i].to,&a[i].g,&a[i].s);
		a[i].id=i;
		b[i]=a[i];
	}
	sort(a+1,a+m+1,cmp_s);
	for(int i=1;i<=m;i++) b[a[i].id].id=i;
	sort(b+1,b+m+1,cmp_g);

//	for(int i=1;i<=m;i++) printf("(%d->%d %d %d)",a[i].from,a[i].to,a[i].g,a[i].s);puts("");
//	for(int i=1;i<=m;i++) printf("(%d->%d %d %d %d)",b[i].from,b[i].to,b[i].g,b[i].s,b[i].id);puts("");

	ll ans=-1;
	for(int i=1;i<=m;i++){
		ins(1,1,m,b[i].id,b[i]);
	//	printf("%d\n",node[1].sz);
	//	for(int j=1;j<=n;j++) printf("%d ",node[1].par[j]);puts("");
		if(node[1].sz!=n-1) continue;
		tmp=Node();
		ll need=query(1,1,m);
		ll sum=b[i].g*vg+need*vs;
		if(ans==-1) ans=sum;else ans=min(ans,sum);
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<utility>
#include<cstdlib>
#include<ctime>
#include<cctype>
#include<string>
using namespace std;
#define mp make_pair
#define pb push_back
#define pf push_front
#define X first
#define Y second
#define lch(x) ((x)<<1)
#define rch(x) (((x)<<1)^1)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int N=205,M=5e4+7;
const ll inf=1e11+7;

int n,m;
ll vg,vs;

struct edge{
	int from,to,id;
	ll g,s;
}a[M],b[M];

bool cmp_g(const edge &a,const edge &b){
	if(a.g!=b.g) return a.g<b.g;
	return a.s<b.s;
}

bool cmp_s(const edge &a,const edge &b){
	if(a.s!=b.s) return a.s<b.s;
	return a.g<b.g;
}

struct Node{
	int par[N],sz;

	Node(){
		sz=0;
		memset(par,-1,sizeof(par));
	}

	int find(int x){
		return par[x]<0?x:par[x]=find(par[x]);
	}

	void join(int x,int y){
		x=find(x),y=find(y);
		if(x==y) return;
		if(par[x]<par[y]){
			par[x]+=par[y];
			par[y]=x;
		} else{
			par[y]+=par[x];
			par[x]=y;
		}
		++sz;
	}

	void merge(const Node &b){
		for(int i=1;i<=n;i++) join(i,b.par[i]);
	}

}node[M<<2],tmp,temp;

void ins(int t,int l,int r,int p,edge &e){
	node[t].join(e.from,e.to);
	if(l==r) return;
	int mid=l+r>>1;
	if(p<=mid) ins(lch(t),l,mid,p,e);
	else ins(rch(t),mid+1,r,p,e);
}

ll query(int t,int l,int r){
	if(l==r) return a[t].s;
	int mid=l+r>>1;
	temp=tmp;
	temp.merge(node[lch(t)]);
	if(temp.sz==n-1){
		return query(lch(t),l,mid);
	}else{
		tmp=temp;
		return query(rch(t),mid+1,r);
	}
}

int main(){
	scanf("%d%d%I64d%I64d",&n,&m,&vg,&vs);
	for(int i=1;i<=m;i++){
		scanf("%d%d%I64d%I64d",&a[i].from,&a[i].to,&a[i].g,&a[i].s);
		a[i].id=i;
		b[i]=a[i];
	}
	sort(a+1,a+m+1,cmp_s);
	for(int i=1;i<=m;i++) b[a[i].id].id=i;
	sort(b+1,b+m+1,cmp_g);

//	for(int i=1;i<=m;i++) printf("(%d->%d %d %d)",a[i].from,a[i].to,a[i].g,a[i].s);puts("");
//	for(int i=1;i<=m;i++) printf("(%d->%d %d %d %d)",b[i].from,b[i].to,b[i].g,b[i].s,b[i].id);puts("");

	ll ans=-1;
	for(int i=1;i<=m;i++){
		ins(1,1,m,b[i].id,b[i]);
	//	printf("%d\n",node[1].sz);
	//	for(int j=1;j<=n;j++) printf("%d ",node[1].par[j]);puts("");
		if(node[1].sz!=n-1) continue;
		tmp=Node();
		ll need=query(1,1,m);
		ll sum=b[i].g*vg+need*vs;
		if(ans==-1) ans=sum;else ans=min(ans,sum);
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<utility>
#include<cstdlib>
#include<ctime>
#include<cctype>
#include<string>
using namespace std;
#define mp make_pair
#define pb push_back
#define pf push_front
#define X first
#define Y second
#define lch(x) ((x)<<1)
#define rch(x) (((x)<<1)^1)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int N=205,M=5e4+7;
const ll inf=1e11+7;

int n,m;
ll vg,vs;

struct edge{
	int from,to,id;
	ll g,s;
}a[M],b[M];

bool cmp_g(const edge &a,const edge &b){
	if(a.g!=b.g) return a.g<b.g;
	return a.s<b.s;
}

bool cmp_s(const edge &a,const edge &b){
	if(a.s!=b.s) return a.s<b.s;
	return a.g<b.g;
}

struct Node{
	int par[N],sz;

	Node(){
		sz=0;
		memset(par,-1,sizeof(par));
	}

	int find(int x){
		return par[x]<0?x:par[x]=find(par[x]);
	}

	void join(int x,int y){
		x=find(x),y=find(y);
		if(x==y) return;
		if(par[x]<par[y]){
			par[x]+=par[y];
			par[y]=x;
		} else{
			par[y]+=par[x];
			par[x]=y;
		}
		++sz;
	}

	void merge(Node &b){
		for(int i=1;i<=n;i++) join(i,b.find(i));
	}

}node[M<<2],tmp,temp;

void ins(int t,int l,int r,int p,edge &e){
	node[t].join(e.from,e.to);
	if(l==r) return;
	int mid=l+r>>1;
	if(p<=mid) ins(lch(t),l,mid,p,e);
	else ins(rch(t),mid+1,r,p,e);
}

ll query(int t,int l,int r){
//	cerr<<"("<<l<<','<<r<<')'<<endl;
	if(l==r) return a[l].s;
	int mid=l+r>>1;
	temp=tmp;
	temp.merge(node[lch(t)]);
	if(temp.sz==n-1){
		return query(lch(t),l,mid);
	}else{
		tmp=temp;
		return query(rch(t),mid+1,r);
	}
}

int main(){
	scanf("%d%d%I64d%I64d",&n,&m,&vg,&vs);
	for(int i=1;i<=m;i++){
		scanf("%d%d%I64d%I64d",&a[i].from,&a[i].to,&a[i].g,&a[i].s);
		a[i].id=i;
		b[i]=a[i];
	}
	sort(a+1,a+m+1,cmp_s);
	for(int i=1;i<=m;i++) b[a[i].id].id=i;
	sort(b+1,b+m+1,cmp_g);

//	for(int i=1;i<=m;i++) printf("(%d->%d %d %d)",a[i].from,a[i].to,a[i].g,a[i].s);puts("");
//	for(int i=1;i<=m;i++) printf("(%d->%d %d %d %d)",b[i].from,b[i].to,b[i].g,b[i].s,b[i].id);puts("");

	ll ans=-1;
	for(int i=1;i<=m;i++){
		ins(1,1,m,b[i].id,b[i]);
	//	printf("%d\n",node[1].sz);
	//	for(int j=1;j<=n;j++) printf("%d ",node[1].par[j]);puts("");
		if(node[1].sz!=n-1) continue;
		tmp=Node();
		ll need=query(1,1,m);
		ll sum=b[i].g*vg+need*vs;
	//	cerr<<need<<' '<<sum<<endl;
		if(ans==-1) ans=sum;else ans=min(ans,sum);
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define pb push_back
typedef long long ll;

const int N=205,M=50005;

struct edge{
	int from,to,nxt;
	ll g,s;
	bool can;

	edge():from(0),to(0),nxt(0),g(0),s(0),can(true){}

	bool operator <(const edge &b)const{
		if(g!=b.g) return g<b.g;
		return s<b.s;
	}

}e[M<<2];
int n,m,par[N],head[N];
vector<int> used;
ll vg,vs;

int find(int x){
	return par[x]<0?x:par[x]=find(par[x]);
}

void join(int x,int y){
	if(x==y) return;
	if(par[x]<par[y]){
		par[x]+=par[y];
		par[y]=x;
	}else{
		par[y]+=par[x];
		par[x]=y;
	}
}

void addedge(int u,int p){
	e[p].nxt=head[u],head[u]=p;
}

int findmax(int u,int parent,int pos){
	for(int p=head[u];p;p=e[p].nxt){
		if(!e[p].can||e[p].to==parent) continue;
		int v=e[p].to;
		if(v==pos){
			return p;
		}else{
			int p2=findmax(v,u,pos);
			if(p2==-1) continue;
			if(e[p2].s<e[p].s) return p;else return p2;
		}
	}
	return -1;
}

int main(){
	scanf("%d%d%I64d%I64d",&n,&m,&vg,&vs);
	for(int i=1;i<=m;i++){
		scanf("%d%d%I64d%I64d",&e[i].from,&e[i].to,&e[i].g,&e[i].s);
	}
	sort(e+1,e+m+1);
	memset(par,-1,sizeof(par));
	int num=0;
	ll need=0,ans=-1;
	for(int i=1;i<=m;i++){
		if(e[i].from==e[i].to) continue;
		e[i+m]=e[i];
		swap(e[i+m].from,e[i+m].to);
	//	printf("%dbegin\n",i);
		int x=find(e[i].from),y=find(e[i].to);
		if(x==y){
			int p=findmax(e[i].from,-1,e[i].to);
		//	printf("p=(%d %d)\n",e[p].from,e[p].to);
			if(e[p].s<=e[i].s) continue;
			if(p>m) p-=m;
			e[p].can=e[p+m].can=false;
			addedge(e[i].from,i);
			addedge(e[i].to,i+m);
			for(int j=0;j<used.size();j++) if(used[j]==p){
				used[j]=i;
				break;
			}
		}else{
			join(x,y);
			addedge(e[i].from,i);
			addedge(e[i].to,i+m);
			++num;
			used.pb(i);
		}
	//	for(int j=0;j<used.size();j++) printf("(%d %d) ",e[used[j]].from,e[used[j]].to);puts("");
		if(num==n-1){
			need=0;
			for(int j=0;j<used.size();j++) need=max(need,e[used[j]].s);
			ll cost=e[i].g*vg+need*vs;
			if(ans==-1) ans=cost;else ans=min(ans,cost);
		}
	//	printf("end%d %d\n",need,ans);
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define pb push_back
typedef long long ll;

const int N=205,M=50005;

struct edge{
	int from,to,nxt;
	ll g,s;
	bool can;

	edge():from(0),to(0),nxt(0),g(0),s(0),can(true){}

	bool operator <(const edge &b)const{
		if(g!=b.g) return g<b.g;
		return s<b.s;
	}

}e[M<<2];
int n,m,par[N],head[N];
vector<int> used;
ll vg,vs;

int find(int x){
	return par[x]<0?x:par[x]=find(par[x]);
}

void join(int x,int y){
	if(x==y) return;
	if(par[x]<par[y]){
		par[x]+=par[y];
		par[y]=x;
	}else{
		par[y]+=par[x];
		par[x]=y;
	}
}

void addedge(int u,int p){
	e[p].nxt=head[u],head[u]=p;
}

int findmax(int u,int parent,int pos){
	for(int p=head[u];p;p=e[p].nxt){
		if(!e[p].can||e[p].to==parent) continue;
		int v=e[p].to;
		if(v==pos){
			return p;
		}else{
			int p2=findmax(v,u,pos);
			if(p2==-1) continue;
			if(e[p2].s<e[p].s) return p;else return p2;
		}
	}
	return -1;
}

int main(){
	scanf("%d%d%I64d%I64d",&n,&m,&vg,&vs);
	for(int i=1;i<=m;i++){
		scanf("%d%d%I64d%I64d",&e[i].from,&e[i].to,&e[i].g,&e[i].s);
	}
	sort(e+1,e+m+1);
	memset(par,-1,sizeof(par));
	int num=0;
	ll need=0,ans=-1;
	for(int i=1;i<=m;i++){
		e[i+m]=e[i];
		swap(e[i+m].from,e[i+m].to);
	//	printf("%dbegin\n",i);
		int x=find(e[i].from),y=find(e[i].to);
		if(x==y){
			int p=findmax(e[i].from,-1,e[i].to);
		//	printf("p=(%d %d)\n",e[p].from,e[p].to);
			if(e[p].s<=e[i].s) continue;
			if(p>m) p-=m;
			e[p].can=e[p+m].can=false;
			addedge(e[i].from,i);
			addedge(e[i].to,i+m);
			for(int j=0;j<used.size();j++) if(used[j]==p){
				used[j]=i;
				break;
			}
		}else{
			join(x,y);
			addedge(e[i].from,i);
			addedge(e[i].to,i+m);
			++num;
			used.pb(i);
		}
	//	for(int j=0;j<used.size();j++) printf("(%d %d) ",e[used[j]].from,e[used[j]].to);puts("");
		if(num==n-1){
			need=0;
			for(int j=0;j<used.size();j++) need=max(need,e[used[j]].s);
			ll cost=e[i].g*vg+need*vs;
			if(ans==-1) ans=cost;else ans=min(ans,cost);
		}
	//	printf("end%d %d\n",need,ans);
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define pb push_back
typedef long long ll;

const int N=205,M=50005;
const ll inf=1e18+7;

struct edge{
	int u,v;
	ll g,s;
}e[M];
int n,m;
ll vg,vs;
int par[N];
vector<int> used(0),newv(0);

bool cmpg(const edge &a,const edge &b){
	if(a.g!=b.g) return a.g<b.g;
	return a.s<b.s;
}

bool cmps(const int a,const int b){
	if(e[a].s!=e[b].s) return e[a].s<e[b].s;
	return e[a].g<e[b].g;
}

int find(int x){
	return par[x]<0?x:par[x]=find(par[x]);
}

void join(int x,int y){
	if(x==y) return;
	if(par[x]<par[y]){
		par[x]+=par[y];
		par[y]=x;
	}else{
		par[y]+=par[x];
		par[x]=y;
	}
}

int main(){
	scanf("%d%d%I64d%I64d",&n,&m,&vg,&vs);
	for(int i=1;i<=m;i++) scanf("%d%d%I64d%I64d",&e[i].u,&e[i].v,&e[i].g,&e[i].s);
	sort(e+1,e+1+m,cmpg);
	ll ans=inf;
	for(int i=1;i<=m;i++){
		newv=used;
		used.clear();
		newv.pb(i);
		sort(newv.begin(),newv.end(),cmps);
		memset(par,-1,sizeof(par));
		ll mx=0;
		for(int j=0;j<newv.size();j++){
			int v=newv[j],x=find(e[v].u),y=find(e[v].v);
			if(x==y) continue;
			mx=max(e[v].s,mx);
			join(x,y);
			used.pb(v);
		}
		if(used.size()==n-1){
			ans=min(ans,e[i].g*vg+mx*vs);
		}
	}
	printf("%I64d\n",ans);
	return 0;
}


/*
 * temp.cpp
 *
 *  Created on: 2012-7-18
 *      Author: BSBandme
 */
#include <iostream>
#include <fstream>
#include <string.h>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
#include <iomanip>
#include <math.h>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <climits>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <sstream>

using namespace std;

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 <ll> vl;
typedef vector <double> vd;
typedef vector <string> vs;
typedef map <string, int> mpsi;
typedef map <double, int> mpdi;
typedef map <int, int> mpii;

const double pi = acos(0.0) * 2.0;
const double eps = 1e-12;
const int step[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

template <class T> inline T abs1(T a) {return a < 0 ? -a : a;}
template <class T> inline T max1(T a, T b, T c = -1234567, T d = -1234567) {
	T ans =  a > b ? a : b;
	if(c != -1234567) ans = max1(ans, c);
	if(d != -1234567) ans = max1(ans, d);
	return ans;
}
template <class T> inline T min1(T a, T b, T c = -1234567, T d = -1234567) {
	T ans = a < b ? a : b;
	if(c != -1234567) ans = min(ans, c);
	if(d != -1234567) ans = min(ans, d);
	return ans;
}
template <class T> inline T gcd1(T a, T b) {
	if(a < b) swap(a, b);
	if(a % b == 0) return b;
	return gcd1(b, a % b);
}
template <class T> inline T lb(T num) {return num & (-num); }
inline int jud(double a, double b){
	if(abs1(a - b) < eps) return 0;
	if(a < b) return -1;
	return 1;
}
template <class t>
inline int find(t val, t *a, int na, bool f_small = 1, bool f_lb = 1){
	if(na == 1) return 0;
	int be = 0, en = na - 1;
	if(a[0] <= a[na - 1]){
		if(f_lb == 0) while(be < en){
			int mid = (be + en + 1) / 2;
			if(jud(a[mid], val) != 1) be = mid;
			else en = mid - 1;
		}else while(be < en){
			int mid = (be + en) / 2;
			if(jud(a[mid], val) != -1) en = mid;
			else be = mid + 1;
		}
		if(f_small && jud(a[be], val) == 1 && be != 0) be--;
		if(!f_small && jud(a[be], val) == -1 && be != na - 1) be++;
	} else {
		if(f_lb) while(be < en){
			int mid = (be + en + 1) / 2;
			if(jud(a[mid], val) != -1) be = mid;
			else en = mid - 1;
		}else while(be < en){
			int mid = (be + en) / 2;
			if(jud(a[mid], val) != 1) en = mid;
			else be = mid + 1;
		}
		if(!f_small && jud(a[be], val) == -1 && be != 0) be--;
		if(f_small && jud(a[be], val) == 1 && be != na - 1) be++;
	}
	return be;
}
inline int bitnum(ull nValue){
    nValue = ((0xaaaaaaaaaaaaaaaaull & nValue)>>1) + (0x5555555555555555ull & nValue);
    nValue = ((0xccccccccccccccccull & nValue)>>2) + (0x3333333333333333ull & nValue);
    nValue = ((0xf0f0f0f0f0f0f0f0ull & nValue)>>4) + (0x0f0f0f0f0f0f0f0full & nValue);
    nValue = ((0xff00ff00ff00ff00ull & nValue)>>8) + (0x00ff00ff00ff00ffull & nValue);
    nValue = ((0xffff0000ffff0000ull & nValue)>>16) + (0x0000ffff0000ffffull & nValue);
    nValue = ((0xffffffff00000000ull & nValue)>>32) + (0x00000000ffffffffull & nValue);
	return nValue;
}
long long pow(long long n, long long m, long long mod = 0){
	long long ans = 1;
	long long k = n;
	while(m){
		if(m & 1) {
			ans *= k;
			if(mod) ans %= mod;
		}
		k *= k;
		if(mod) k %= mod;
		m >>= 1;
	}
	return ans;
}

const int maxn = 110000;
int orig[maxn], n;
struct node{
	int nxt[2];
	int val;
} arr[maxn * 2];
int larr = 2;

int main(){
//	freopen("input.txt","r", stdin);
	scanf("%d", &n);
	int ans = 0;
	for(int i = 0; i < n; i++) scanf("%d", orig + i);
	for(int i = 0; i < n; i++){
		int head = 1;
		int j = 31;
		bool f = 1;
		for(j = 31; j >= 0; j--){
			int bit = 0;
			if((1 << j) & orig[i])
				bit = 1;
			if(arr[head].nxt[bit] == 0) {
				arr[head].nxt[bit] = larr;
				head = larr++;
			}else head = arr[head].nxt[bit];
			arr[head].val = j;
		}
		int num = 0; head = 1;
		j = 31;
		while((orig[i] & (1 << j)) == 0){
			if(arr[head].nxt[0] == 0) {
				f = 0;
				break;
			}
			head = arr[head].nxt[0];
			j--;
		}
		if(f) for(; j >= 0; j--){
			int bit = 1;
			if((1 << j) & orig[i]) bit = 0;
			if(arr[head].nxt[bit] == 0 || (bit == 0 && arr[head].nxt[bit] < arr[head].nxt[1 - bit])) {
				head = arr[head].nxt[1 - bit];
				num |= (1 - bit) << j;
			}else{
				head = arr[head].nxt[bit];
				num |= (bit) << j;
			}
		}
		ans = max1(num ^ orig[i], ans, orig[i]);
	}
	memset(arr, 0, sizeof(arr)); larr = 2;
	for(int i = n - 1; i >= 0; i--){
		int head = 1;
		for(int j = 31; j >= 0; j--){
			int bit = 0;
			if((1 << j) & orig[i])
				bit = 1;
			if(arr[head].nxt[bit] == 0) {
				arr[head].nxt[bit] = larr;
				head = larr++;
			}else head = arr[head].nxt[bit];
			arr[head].val = j;
		}
		bool f = 1;
		int num = 0; head = 1; int j = 31;
		while((orig[i] & (1 << j)) == 0){
			if(arr[head].nxt[0] == 0) {
				f = 0;
				break;
			}
			head = arr[head].nxt[0];
			j--;
		}
		if(f) for(; j >= 0; j--){
			int bit = 1;
			if((1 << j) & orig[i]) bit = 0;
			if(arr[head].nxt[bit] == 0 || (bit == 0 && arr[head].nxt[bit] > arr[head].nxt[1 - bit])) {
				head = arr[head].nxt[1 - bit];
				num |= (1 - bit) << j;
			}else{
				head = arr[head].nxt[bit];
				num |= (bit) << j;
			}
		}
		ans = max1(num ^ orig[i], ans, orig[i]);
	}
	cout << ans << endl;

	return 0;
}


/*
 * temp.cpp
 *
 *  Created on: 2012-7-18
 *      Author: BSBandme
 */
#include <iostream>
#include <fstream>
#include <string.h>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
#include <iomanip>
#include <math.h>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <climits>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <sstream>

using namespace std;

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 <ll> vl;
typedef vector <double> vd;
typedef vector <string> vs;
typedef map <string, int> mpsi;
typedef map <double, int> mpdi;
typedef map <int, int> mpii;

const double pi = acos(0.0) * 2.0;
const double eps = 1e-12;
const int step[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

template <class T> inline T abs1(T a) {return a < 0 ? -a : a;}
template <class T> inline T max1(T a, T b, T c = -1234567, T d = -1234567) {
	T ans =  a > b ? a : b;
	if(c != -1234567) ans = max1(ans, c);
	if(d != -1234567) ans = max1(ans, d);
	return ans;
}
template <class T> inline T min1(T a, T b, T c = -1234567, T d = -1234567) {
	T ans = a < b ? a : b;
	if(c != -1234567) ans = min(ans, c);
	if(d != -1234567) ans = min(ans, d);
	return ans;
}
template <class T> inline T gcd1(T a, T b) {
	if(a < b) swap(a, b);
	if(a % b == 0) return b;
	return gcd1(b, a % b);
}
template <class T> inline T lb(T num) {return num & (-num); }
inline int jud(double a, double b){
	if(abs1(a - b) < eps) return 0;
	if(a < b) return -1;
	return 1;
}
template <typename it, typename t1>
inline int find(t1 val, it a, int na, bool f_small = 1, bool f_lb = 1){
	if(na == 1) return 0;
	int be = 0, en = na - 1;
	if(*a <= *(a + na - 1)){
		if(f_lb == 0) while(be < en){
			int mid = (be + en + 1) / 2;
			if(jud(*(a + mid), val) != 1) be = mid;
			else en = mid - 1;
		}else while(be < en){
			int mid = (be + en) / 2;
			if(jud(*(a + mid), val) != -1) en = mid;
			else be = mid + 1;
		}
		if(f_small && jud(*(a + be), val) == 1 && be != 0) be--;
		if(!f_small && jud(*(a + be), val) == -1 && be != na - 1) be++;
	} else {
		if(f_lb) while(be < en){
			int mid = (be + en + 1) / 2;
			if(jud(*(a + mid), val) != -1) be = mid;
			else en = mid - 1;
		}else while(be < en){
			int mid = (be + en) / 2;
			if(jud(*(a + mid), val) != 1) en = mid;
			else be = mid + 1;
		}
		if(!f_small && jud(*(a + be), val) == -1 && be != 0) be--;
		if(f_small && jud(*(a + be), val) == 1 && be != na - 1) be++;
	}
	return be;
}
inline int bitnum(ull nValue){
    nValue = ((0xaaaaaaaaaaaaaaaaull & nValue)>>1) + (0x5555555555555555ull & nValue);
    nValue = ((0xccccccccccccccccull & nValue)>>2) + (0x3333333333333333ull & nValue);
    nValue = ((0xf0f0f0f0f0f0f0f0ull & nValue)>>4) + (0x0f0f0f0f0f0f0f0full & nValue);
    nValue = ((0xff00ff00ff00ff00ull & nValue)>>8) + (0x00ff00ff00ff00ffull & nValue);
    nValue = ((0xffff0000ffff0000ull & nValue)>>16) + (0x0000ffff0000ffffull & nValue);
    nValue = ((0xffffffff00000000ull & nValue)>>32) + (0x00000000ffffffffull & nValue);
	return nValue;
}
long long pow(long long n, long long m, long long mod = 0){
	long long ans = 1;
	long long k = n;
	while(m){
		if(m & 1) {
			ans *= k;
			if(mod) ans %= mod;
		}
		k *= k;
		if(mod) k %= mod;
		m >>= 1;
	}
	return ans;
}

const int maxn = 100100;
int n;
int arr[maxn], st[maxn], lst;

int main(){
//	freopen("input.txt","r", stdin);
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", arr + i);
	int ans = 0;
//	for (int i = 0; i < n; ++i) ans = max1(ans, arr[i]);
	for(int j = 0; j < n; j++){
		while(lst && st[lst - 1] < arr[j]){
			ans = max1(arr[j] ^ st[lst - 1], ans);
			lst--;
		}
		st[lst++] = arr[j];
	}
	lst = 0;
	for(int j = n - 1; j >= 0; j--){
		while(lst && st[lst - 1] < arr[j]){
			ans = max1(arr[j] ^ st[lst - 1], ans);
			lst--;
		}
		st[lst++] = arr[j];
	}
	cout << ans << endl;

	return 0;
}


/*
 * temp.cpp
 *
 *  Created on: 2012-7-18
 *      Author: BSBandme
 */
#include <iostream>
#include <fstream>
#include <string.h>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
#include <iomanip>
#include <math.h>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <climits>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <sstream>

using namespace std;

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 <ll> vl;
typedef vector <double> vd;
typedef vector <string> vs;
typedef map <string, int> mpsi;
typedef map <double, int> mpdi;
typedef map <int, int> mpii;

const double pi = acos(0.0) * 2.0;
const double eps = 1e-12;
const int step[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

template <class T> inline T abs1(T a) {return a < 0 ? -a : a;}
template <class T> inline T max1(T a, T b, T c = -1234567, T d = -1234567) {
	T ans =  a > b ? a : b;
	if(c != -1234567) ans = max1(ans, c);
	if(d != -1234567) ans = max1(ans, d);
	return ans;
}
template <class T> inline T min1(T a, T b, T c = -1234567, T d = -1234567) {
	T ans = a < b ? a : b;
	if(c != -1234567) ans = min(ans, c);
	if(d != -1234567) ans = min(ans, d);
	return ans;
}
template <class T> inline T gcd1(T a, T b) {
	if(a < b) swap(a, b);
	if(a % b == 0) return b;
	return gcd1(b, a % b);
}
template <class T> inline T lb(T num) {return num & (-num); }
inline int jud(double a, double b){
	if(abs1(a - b) < eps) return 0;
	if(a < b) return -1;
	return 1;
}
template <class t>
inline int find(t val, t *a, int na, bool f_small = 1, bool f_lb = 1){
	if(na == 1) return 0;
	int be = 0, en = na - 1;
	if(a[0] <= a[na - 1]){
		if(f_lb == 0) while(be < en){
			int mid = (be + en + 1) / 2;
			if(jud(a[mid], val) != 1) be = mid;
			else en = mid - 1;
		}else while(be < en){
			int mid = (be + en) / 2;
			if(jud(a[mid], val) != -1) en = mid;
			else be = mid + 1;
		}
		if(f_small && jud(a[be], val) == 1 && be != 0) be--;
		if(!f_small && jud(a[be], val) == -1 && be != na - 1) be++;
	} else {
		if(f_lb) while(be < en){
			int mid = (be + en + 1) / 2;
			if(jud(a[mid], val) != -1) be = mid;
			else en = mid - 1;
		}else while(be < en){
			int mid = (be + en) / 2;
			if(jud(a[mid], val) != 1) en = mid;
			else be = mid + 1;
		}
		if(!f_small && jud(a[be], val) == -1 && be != 0) be--;
		if(f_small && jud(a[be], val) == 1 && be != na - 1) be++;
	}
	return be;
}
inline int bitnum(ull nValue){
    nValue = ((0xaaaaaaaaaaaaaaaaull & nValue)>>1) + (0x5555555555555555ull & nValue);
    nValue = ((0xccccccccccccccccull & nValue)>>2) + (0x3333333333333333ull & nValue);
    nValue = ((0xf0f0f0f0f0f0f0f0ull & nValue)>>4) + (0x0f0f0f0f0f0f0f0full & nValue);
    nValue = ((0xff00ff00ff00ff00ull & nValue)>>8) + (0x00ff00ff00ff00ffull & nValue);
    nValue = ((0xffff0000ffff0000ull & nValue)>>16) + (0x0000ffff0000ffffull & nValue);
    nValue = ((0xffffffff00000000ull & nValue)>>32) + (0x00000000ffffffffull & nValue);
	return nValue;
}
long long pow(long long n, long long m, long long mod = 0){
	long long ans = 1;
	long long k = n;
	while(m){
		if(m & 1) {
			ans *= k;
			if(mod) ans %= mod;
		}
		k *= k;
		if(mod) k %= mod;
		m >>= 1;
	}
	return ans;
}

const int maxn = 110000;
int orig[maxn], n;
struct node{
	int nxt[2];
	int val;
} arr[maxn * 2];
int larr = 2;

int main(){
//	freopen("input.txt","r", stdin);
	scanf("%d", &n);
	int ans = 0;
	for(int i = 0; i < n; i++) scanf("%d", orig + i);
	for(int i = 0; i < n; i++){
		int head = 1;
		int j = 31;
		bool f = 1;
		for(j = 31; j >= 0; j--){
			int bit = 0;
			if((1 << j) & orig[i])
				bit = 1;
			if(arr[head].nxt[bit] == 0) {
				arr[head].nxt[bit] = larr;
				head = larr++;
			}else head = arr[head].nxt[bit];
			arr[head].val = j;
		}
		int num = 0; head = 1;
		j = 31;
		while((orig[i] & (1 << j)) == 0){
			if(arr[head].nxt[0] == 0 || (arr[head].nxt[1] != 0 && arr[head].nxt[1] > arr[head].nxt[0])) {
				f = 0;
				break;
			}
			head = arr[head].nxt[0];
			j--;
		}
		if(f) for(; j >= 0; j--){
			int bit = 1;
			if((1 << j) & orig[i]) bit = 0;
			if(arr[head].nxt[bit] == 0 || (bit == 0 && arr[head].nxt[bit] < arr[head].nxt[1 - bit])) {
				head = arr[head].nxt[1 - bit];
				num |= (1 - bit) << j;
			}else{
				head = arr[head].nxt[bit];
				num |= (bit) << j;
			}
		}
		ans = max1(num ^ orig[i], ans, orig[i]);
	}
	memset(arr, 0, sizeof(arr)); larr = 2;
	for(int i = n - 1; i >= 0; i--){
		int head = 1;
		for(int j = 31; j >= 0; j--){
			int bit = 0;
			if((1 << j) & orig[i])
				bit = 1;
			if(arr[head].nxt[bit] == 0) {
				arr[head].nxt[bit] = larr;
				head = larr++;
			}else head = arr[head].nxt[bit];
			arr[head].val = j;
		}
		bool f = 1;
		int num = 0; head = 1; int j = 31;
		while((orig[i] & (1 << j)) == 0){
			if(arr[head].nxt[0] == 0 || (arr[head].nxt[1] != 0 && arr[head].nxt[1] < arr[head].nxt[0])) {
				f = 0;
				break;
			}
			head = arr[head].nxt[0];
			j--;
		}
		if(f) for(; j >= 0; j--){
			int bit = 1;
			if((1 << j) & orig[i]) bit = 0;
			if(arr[head].nxt[bit] == 0 || (bit == 0 && arr[head].nxt[bit] > arr[head].nxt[1 - bit])) {
				head = arr[head].nxt[1 - bit];
				num |= (1 - bit) << j;
			}else{
				head = arr[head].nxt[bit];
				num |= (bit) << j;
			}
		}
		ans = max1(num ^ orig[i], ans, orig[i]);
	}
	cout << ans << endl;

	return 0;
}


/*
 * temp.cpp
 *
 *  Created on: 2012-7-18
 *      Author: BSBandme
 */
#include <iostream>
#include <fstream>
#include <string.h>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
#include <iomanip>
#include <math.h>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <climits>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <sstream>

using namespace std;

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 <ll> vl;
typedef vector <double> vd;
typedef vector <string> vs;
typedef map <string, int> mpsi;
typedef map <double, int> mpdi;
typedef map <int, int> mpii;

const double pi = acos(0.0) * 2.0;
const double eps = 1e-12;
const int step[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

template <class T> inline T abs1(T a) {return a < 0 ? -a : a;}
template <class T> inline T max1(T a, T b, T c = -1234567, T d = -1234567) {
	T ans =  a > b ? a : b;
	if(c != -1234567) ans = max1(ans, c);
	if(d != -1234567) ans = max1(ans, d);
	return ans;
}
template <class T> inline T min1(T a, T b, T c = -1234567, T d = -1234567) {
	T ans = a < b ? a : b;
	if(c != -1234567) ans = min(ans, c);
	if(d != -1234567) ans = min(ans, d);
	return ans;
}
template <class T> inline T gcd1(T a, T b) {
	if(a < b) swap(a, b);
	if(a % b == 0) return b;
	return gcd1(b, a % b);
}
template <class T> inline T lb(T num) {return num & (-num); }
inline int jud(double a, double b){
	if(abs1(a - b) < eps) return 0;
	if(a < b) return -1;
	return 1;
}
template <class t>
inline int find(t val, t *a, int na, bool f_small = 1, bool f_lb = 1){
	if(na == 1) return 0;
	int be = 0, en = na - 1;
	if(a[0] <= a[na - 1]){
		if(f_lb == 0) while(be < en){
			int mid = (be + en + 1) / 2;
			if(jud(a[mid], val) != 1) be = mid;
			else en = mid - 1;
		}else while(be < en){
			int mid = (be + en) / 2;
			if(jud(a[mid], val) != -1) en = mid;
			else be = mid + 1;
		}
		if(f_small && jud(a[be], val) == 1 && be != 0) be--;
		if(!f_small && jud(a[be], val) == -1 && be != na - 1) be++;
	} else {
		if(f_lb) while(be < en){
			int mid = (be + en + 1) / 2;
			if(jud(a[mid], val) != -1) be = mid;
			else en = mid - 1;
		}else while(be < en){
			int mid = (be + en) / 2;
			if(jud(a[mid], val) != 1) en = mid;
			else be = mid + 1;
		}
		if(!f_small && jud(a[be], val) == -1 && be != 0) be--;
		if(f_small && jud(a[be], val) == 1 && be != na - 1) be++;
	}
	return be;
}
inline int bitnum(ull nValue){
    nValue = ((0xaaaaaaaaaaaaaaaaull & nValue)>>1) + (0x5555555555555555ull & nValue);
    nValue = ((0xccccccccccccccccull & nValue)>>2) + (0x3333333333333333ull & nValue);
    nValue = ((0xf0f0f0f0f0f0f0f0ull & nValue)>>4) + (0x0f0f0f0f0f0f0f0full & nValue);
    nValue = ((0xff00ff00ff00ff00ull & nValue)>>8) + (0x00ff00ff00ff00ffull & nValue);
    nValue = ((0xffff0000ffff0000ull & nValue)>>16) + (0x0000ffff0000ffffull & nValue);
    nValue = ((0xffffffff00000000ull & nValue)>>32) + (0x00000000ffffffffull & nValue);
	return nValue;
}
long long pow(long long n, long long m, long long mod = 0){
	long long ans = 1;
	long long k = n;
	while(m){
		if(m & 1) {
			ans *= k;
			if(mod) ans %= mod;
		}
		k *= k;
		if(mod) k %= mod;
		m >>= 1;
	}
	return ans;
}

const int maxn = 110000;
int orig[maxn], n;
struct node{
	int nxt[2];
	int val;
} arr[maxn * 2];
int larr = 2;

int main(){
//	freopen("input.txt","r", stdin);
	scanf("%d", &n);
	int ans = 0;
	for(int i = 0; i < n; i++) scanf("%d", orig + i);
	for(int i = 0; i < n; i++){
		int head = 1;
		int j = 31;
		bool f = 1;
		for(j = 31; j >= 0; j--){
			int bit = 0;
			if((1 << j) & orig[i])
				bit = 1;
			if(arr[head].nxt[bit] == 0) {
				arr[head].nxt[bit] = larr;
				head = larr++;
			}else head = arr[head].nxt[bit];
			arr[head].val = i;
		}
		int num = 0; head = 1;
		j = 31;
		while((orig[i] & (1 << j)) == 0){
			if(arr[head].nxt[0] == 0 || (arr[head].nxt[1] != 0 && arr[arr[head].nxt[1]].val > arr[arr[head].nxt[0]].val)) {
				f = 0;
				break;
			}
			head = arr[head].nxt[0];
			j--;
		}
		if(f) for(; j >= 0; j--){
			int bit = 1;
			if((1 << j) & orig[i]) bit = 0;
			if(arr[head].nxt[bit] == 0 || (bit == 0 && arr[arr[head].nxt[bit]].val < arr[arr[head].nxt[1 - bit]].val && arr[arr[head].nxt[1 - bit]].val != i)) {
				head = arr[head].nxt[1 - bit];
				num |= (1 - bit) << j;
			}else{
				head = arr[head].nxt[bit];
				num |= (bit) << j;
			}
		}
		ans = max1(num ^ orig[i], ans, orig[i]);
	}
	memset(arr, 0, sizeof(arr)); larr = 2;
	for(int i = n - 1; i >= 0; i--){
		int head = 1;
		for(int j = 31; j >= 0; j--){
			int bit = 0;
			if((1 << j) & orig[i])
				bit = 1;
			if(arr[head].nxt[bit] == 0) {
				arr[head].nxt[bit] = larr;
				head = larr++;
			}else head = arr[head].nxt[bit];
			arr[head].val = i;
		}
		bool f = 1;
		int num = 0; head = 1; int j = 31;
		while((orig[i] & (1 << j)) == 0){
			if(arr[head].nxt[0] == 0 || (arr[head].nxt[1] != 0 && arr[arr[head].nxt[1]].val < arr[arr[head].nxt[0]].val)) {
				f = 0;
				break;
			}
			head = arr[head].nxt[0];
			j--;
		}
		if(f) for(; j >= 0; j--){
			int bit = 1;
			if((1 << j) & orig[i]) bit = 0;
			if((arr[head].nxt[bit] == 0) || (bit == 0 && arr[arr[head].nxt[bit]].val > arr[arr[head].nxt[1 - bit]].val && arr[arr[head].nxt[1 - bit]].val != i)) {
				head = arr[head].nxt[1 - bit];
				num |= (1 - bit) << j;
			}else{
				head = arr[head].nxt[bit];
				num |= (bit) << j;
			}
		}
		ans = max1(num ^ orig[i], ans, orig[i]);
	}
	cout << ans << endl;

	return 0;
}


/*
 * temp.cpp
 *
 *  Created on: 2012-7-18
 *      Author: BSBandme
 */
#include <iostream>
#include <fstream>
#include <string.h>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
#include <iomanip>
#include <math.h>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <climits>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <sstream>

using namespace std;

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 <ll> vl;
typedef vector <double> vd;
typedef vector <string> vs;
typedef map <string, int> mpsi;
typedef map <double, int> mpdi;
typedef map <int, int> mpii;

const double pi = acos(0.0) * 2.0;
const double eps = 1e-12;
const int step[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

template <class T> inline T abs1(T a) {return a < 0 ? -a : a;}
template <class T> inline T max1(T a, T b, T c = -1234567, T d = -1234567) {
	T ans =  a > b ? a : b;
	if(c != -1234567) ans = max1(ans, c);
	if(d != -1234567) ans = max1(ans, d);
	return ans;
}
template <class T> inline T min1(T a, T b, T c = -1234567, T d = -1234567) {
	T ans = a < b ? a : b;
	if(c != -1234567) ans = min(ans, c);
	if(d != -1234567) ans = min(ans, d);
	return ans;
}
template <class T> inline T gcd1(T a, T b) {
	if(a < b) swap(a, b);
	if(a % b == 0) return b;
	return gcd1(b, a % b);
}
template <class T> inline T lb(T num) {return num & (-num); }
inline int jud(double a, double b){
	if(abs1(a - b) < eps) return 0;
	if(a < b) return -1;
	return 1;
}
template <class t>
inline int find(t val, t *a, int na, bool f_small = 1, bool f_lb = 1){
	if(na == 1) return 0;
	int be = 0, en = na - 1;
	if(a[0] <= a[na - 1]){
		if(f_lb == 0) while(be < en){
			int mid = (be + en + 1) / 2;
			if(jud(a[mid], val) != 1) be = mid;
			else en = mid - 1;
		}else while(be < en){
			int mid = (be + en) / 2;
			if(jud(a[mid], val) != -1) en = mid;
			else be = mid + 1;
		}
		if(f_small && jud(a[be], val) == 1 && be != 0) be--;
		if(!f_small && jud(a[be], val) == -1 && be != na - 1) be++;
	} else {
		if(f_lb) while(be < en){
			int mid = (be + en + 1) / 2;
			if(jud(a[mid], val) != -1) be = mid;
			else en = mid - 1;
		}else while(be < en){
			int mid = (be + en) / 2;
			if(jud(a[mid], val) != 1) en = mid;
			else be = mid + 1;
		}
		if(!f_small && jud(a[be], val) == -1 && be != 0) be--;
		if(f_small && jud(a[be], val) == 1 && be != na - 1) be++;
	}
	return be;
}
inline int bitnum(ull nValue){
    nValue = ((0xaaaaaaaaaaaaaaaaull & nValue)>>1) + (0x5555555555555555ull & nValue);
    nValue = ((0xccccccccccccccccull & nValue)>>2) + (0x3333333333333333ull & nValue);
    nValue = ((0xf0f0f0f0f0f0f0f0ull & nValue)>>4) + (0x0f0f0f0f0f0f0f0full & nValue);
    nValue = ((0xff00ff00ff00ff00ull & nValue)>>8) + (0x00ff00ff00ff00ffull & nValue);
    nValue = ((0xffff0000ffff0000ull & nValue)>>16) + (0x0000ffff0000ffffull & nValue);
    nValue = ((0xffffffff00000000ull & nValue)>>32) + (0x00000000ffffffffull & nValue);
	return nValue;
}
long long pow(long long n, long long m, long long mod = 0){
	long long ans = 1;
	long long k = n;
	while(m){
		if(m & 1) {
			ans *= k;
			if(mod) ans %= mod;
		}
		k *= k;
		if(mod) k %= mod;
		m >>= 1;
	}
	return ans;
}

const int maxn = 110100;
int orig[maxn], n;
struct node{
	int nxt[2];
	int val;
} arr[maxn * 2];
int larr = 2;

int main(){
//	freopen("input.txt","r", stdin);
	scanf("%d", &n);
	int ans = 0;
	for(int i = 0; i < n; i++) scanf("%d", orig + i);
	for(int i = 0; i < n; i++){
		int head = 1;
		int j = 31;
		bool f = 1;
		for(j = 31; j >= 0; j--){
			int bit = 0;
			if((1 << j) & orig[i])
				bit = 1;
			if(arr[head].nxt[bit] == 0) {
				arr[head].nxt[bit] = larr;
				head = larr++;
			}else head = arr[head].nxt[bit];
			arr[head].val = j;
		}
		int num = 0; head = 1;
		while(orig[i] & (1 << j) == 0){
			if(arr[head].nxt[0] == 0) {
				f = 0;
				break;
			}
			head = arr[head].nxt[0];
		}
		if(f) for(; j >= 0; j--){
			int bit = 1;
			if((1 << j) & orig[i]) bit = 0;
			if(arr[head].nxt[bit] == 0 || (bit == 0 && arr[head].nxt[bit] < arr[head].nxt[1 - bit])) {
				head = arr[head].nxt[1 - bit];
				num |= (1 - bit) << j;
			}else{
				head = arr[head].nxt[bit];
				num |= (bit) << j;
			}
		}
		ans = max1(num ^ orig[i], ans, orig[i]);
	}
	memset(arr, 0, sizeof(arr));
	for(int i = n - 1; i >= 0; i--){
		int head = 1;
		for(int j = 31; j >= 0; j--){
			int bit = 0;
			if((1 << j) & orig[i])
				bit = 1;
			if(arr[head].nxt[bit] == 0) {
				arr[head].nxt[bit] = larr;
				head = larr++;
			}else head = arr[head].nxt[bit];
			arr[head].val = j;
		}
		bool f = 1;
		int num = 0; head = 1; int j = 31;
		while(orig[i] & (1 << j) == 0){
			if(arr[head].nxt[0] == 0) {
				f = 0;
				break;
			}
			head = arr[head].nxt[0];
		}
		if(f) for(; j >= 0; j--){
			int bit = 1;
			if((1 << j) & orig[i]) bit = 0;
			if(arr[head].nxt[bit] == 0 || (bit == 0 && arr[head].nxt[bit] > arr[head].nxt[1 - bit])) {
				head = arr[head].nxt[1 - bit];
				num |= (1 - bit) << j;
			}else{
				head = arr[head].nxt[bit];
				num |= (bit) << j;
			}
		}
		ans = max1(num ^ orig[i], ans, orig[i]);
	}
	cout << ans << endl;

	return 0;
}


/*
 * temp.cpp
 *
 *  Created on: 2012-7-18
 *      Author: BSBandme
 */
#include <iostream>
#include <fstream>
#include <string.h>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
#include <iomanip>
#include <math.h>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <climits>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <sstream>

using namespace std;

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 <ll> vl;
typedef vector <double> vd;
typedef vector <string> vs;
typedef map <string, int> mpsi;
typedef map <double, int> mpdi;
typedef map <int, int> mpii;

const double pi = acos(0.0) * 2.0;
const double eps = 1e-12;
const int step[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

template <class T> inline T abs1(T a) {return a < 0 ? -a : a;}
template <class T> inline T max1(T a, T b, T c = -1234567, T d = -1234567) {
	T ans =  a > b ? a : b;
	if(c != -1234567) ans = max1(ans, c);
	if(d != -1234567) ans = max1(ans, d);
	return ans;
}
template <class T> inline T min1(T a, T b, T c = -1234567, T d = -1234567) {
	T ans = a < b ? a : b;
	if(c != -1234567) ans = min(ans, c);
	if(d != -1234567) ans = min(ans, d);
	return ans;
}
template <class T> inline T gcd1(T a, T b) {
	if(a < b) swap(a, b);
	if(a % b == 0) return b;
	return gcd1(b, a % b);
}
template <class T> inline T lb(T num) {return num & (-num); }
inline int jud(double a, double b){
	if(abs1(a - b) < eps) return 0;
	if(a < b) return -1;
	return 1;
}
template <class t>
inline int find(t val, t *a, int na, bool f_small = 1, bool f_lb = 1){
	if(na == 1) return 0;
	int be = 0, en = na - 1;
	if(a[0] <= a[na - 1]){
		if(f_lb == 0) while(be < en){
			int mid = (be + en + 1) / 2;
			if(jud(a[mid], val) != 1) be = mid;
			else en = mid - 1;
		}else while(be < en){
			int mid = (be + en) / 2;
			if(jud(a[mid], val) != -1) en = mid;
			else be = mid + 1;
		}
		if(f_small && jud(a[be], val) == 1 && be != 0) be--;
		if(!f_small && jud(a[be], val) == -1 && be != na - 1) be++;
	} else {
		if(f_lb) while(be < en){
			int mid = (be + en + 1) / 2;
			if(jud(a[mid], val) != -1) be = mid;
			else en = mid - 1;
		}else while(be < en){
			int mid = (be + en) / 2;
			if(jud(a[mid], val) != 1) en = mid;
			else be = mid + 1;
		}
		if(!f_small && jud(a[be], val) == -1 && be != 0) be--;
		if(f_small && jud(a[be], val) == 1 && be != na - 1) be++;
	}
	return be;
}
inline int bitnum(ull nValue){
    nValue = ((0xaaaaaaaaaaaaaaaaull & nValue)>>1) + (0x5555555555555555ull & nValue);
    nValue = ((0xccccccccccccccccull & nValue)>>2) + (0x3333333333333333ull & nValue);
    nValue = ((0xf0f0f0f0f0f0f0f0ull & nValue)>>4) + (0x0f0f0f0f0f0f0f0full & nValue);
    nValue = ((0xff00ff00ff00ff00ull & nValue)>>8) + (0x00ff00ff00ff00ffull & nValue);
    nValue = ((0xffff0000ffff0000ull & nValue)>>16) + (0x0000ffff0000ffffull & nValue);
    nValue = ((0xffffffff00000000ull & nValue)>>32) + (0x00000000ffffffffull & nValue);
	return nValue;
}
long long pow(long long n, long long m, long long mod = 0){
	long long ans = 1;
	long long k = n;
	while(m){
		if(m & 1) {
			ans *= k;
			if(mod) ans %= mod;
		}
		k *= k;
		if(mod) k %= mod;
		m >>= 1;
	}
	return ans;
}

const int maxn = 110100;
int orig[maxn], n;
struct node{
	int nxt[2];
	int val;
} arr[maxn * 2];
int larr = 2;

int main(){
//	freopen("input.txt","r", stdin);
	scanf("%d", &n);
	int ans = 0;
	for(int i = 0; i < n; i++) scanf("%d", orig + i);
	for(int i = 0; i < n; i++){
		int head = 1;
		for(int j = 31; j >= 0; j--){
			int bit = 0;
			if((1 << j) & orig[i])
				bit = 1;
			if(arr[head].nxt[bit] == 0) {
				arr[head].nxt[bit] = larr;
				head = larr++;
			}else head = arr[head].nxt[bit];
			arr[head].val = j;
		}
		int num = 0; head = 1;
		for(int j = 31; j >= 0; j--){
			int bit = 1;
			if((1 << j) & orig[i]) bit = 0;
			if(arr[head].nxt[bit] == 0 || (bit == 0 && arr[head].nxt[bit] < arr[head].nxt[1 - bit])) {
				head = arr[head].nxt[1 - bit];
				num |= (1 - bit) << j;
			}else{
				head = arr[head].nxt[bit];
				num |= (bit) << j;
			}
		}
		ans = max1(num ^ orig[i], ans, orig[i]);
	}
	memset(arr, 0, sizeof(arr));
	for(int i = n - 1; i >= 0; i--){
		int head = 1;
		for(int j = 31; j >= 0; j--){
			int bit = 0;
			if((1 << j) & orig[i])
				bit = 1;
			if(arr[head].nxt[bit] == 0) {
				arr[head].nxt[bit] = larr;
				head = larr++;
			}else head = arr[head].nxt[bit];
			arr[head].val = j;
		}
		int num = 0; head = 1;
		for(int j = 31; j >= 0; j--){
			int bit = 1;
			if((1 << j) & orig[i]) bit = 0;
			if(arr[head].nxt[bit] == 0 || (bit == 0 && arr[head].nxt[bit] > arr[head].nxt[1 - bit])) {
				head = arr[head].nxt[1 - bit];
				num |= (1 - bit) << j;
			}else{
				head = arr[head].nxt[bit];
				num |= (bit) << j;
			}
		}
		ans = max1(num ^ orig[i], ans, orig[i]);
	}
	cout << ans << endl;

	return 0;
}


/*
 * temp.cpp
 *
 *  Created on: 2012-7-18
 *      Author: BSBandme
 */
#include <iostream>
#include <fstream>
#include <string.h>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
#include <iomanip>
#include <math.h>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <climits>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <sstream>

using namespace std;

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 <ll> vl;
typedef vector <double> vd;
typedef vector <string> vs;
typedef map <string, int> mpsi;
typedef map <double, int> mpdi;
typedef map <int, int> mpii;

const double pi = acos(0.0) * 2.0;
const double eps = 1e-12;
const int step[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

template <class T> inline T abs1(T a) {return a < 0 ? -a : a;}
template <class T> inline T max1(T a, T b, T c = -1234567, T d = -1234567) {
	T ans =  a > b ? a : b;
	if(c != -1234567) ans = max1(ans, c);
	if(d != -1234567) ans = max1(ans, d);
	return ans;
}
template <class T> inline T min1(T a, T b, T c = -1234567, T d = -1234567) {
	T ans = a < b ? a : b;
	if(c != -1234567) ans = min(ans, c);
	if(d != -1234567) ans = min(ans, d);
	return ans;
}
template <class T> inline T gcd1(T a, T b) {
	if(a < b) swap(a, b);
	if(a % b == 0) return b;
	return gcd1(b, a % b);
}
template <class T> inline T lb(T num) {return num & (-num); }
inline int jud(double a, double b){
	if(abs1(a - b) < eps) return 0;
	if(a < b) return -1;
	return 1;
}
template <typename it, typename t1>
inline int find(t1 val, it a, int na, bool f_small = 1, bool f_lb = 1){
	if(na == 1) return 0;
	int be = 0, en = na - 1;
	if(*a <= *(a + na - 1)){
		if(f_lb == 0) while(be < en){
			int mid = (be + en + 1) / 2;
			if(jud(*(a + mid), val) != 1) be = mid;
			else en = mid - 1;
		}else while(be < en){
			int mid = (be + en) / 2;
			if(jud(*(a + mid), val) != -1) en = mid;
			else be = mid + 1;
		}
		if(f_small && jud(*(a + be), val) == 1 && be != 0) be--;
		if(!f_small && jud(*(a + be), val) == -1 && be != na - 1) be++;
	} else {
		if(f_lb) while(be < en){
			int mid = (be + en + 1) / 2;
			if(jud(*(a + mid), val) != -1) be = mid;
			else en = mid - 1;
		}else while(be < en){
			int mid = (be + en) / 2;
			if(jud(*(a + mid), val) != 1) en = mid;
			else be = mid + 1;
		}
		if(!f_small && jud(*(a + be), val) == -1 && be != 0) be--;
		if(f_small && jud(*(a + be), val) == 1 && be != na - 1) be++;
	}
	return be;
}
inline int bitnum(ull nValue){
    nValue = ((0xaaaaaaaaaaaaaaaaull & nValue)>>1) + (0x5555555555555555ull & nValue);
    nValue = ((0xccccccccccccccccull & nValue)>>2) + (0x3333333333333333ull & nValue);
    nValue = ((0xf0f0f0f0f0f0f0f0ull & nValue)>>4) + (0x0f0f0f0f0f0f0f0full & nValue);
    nValue = ((0xff00ff00ff00ff00ull & nValue)>>8) + (0x00ff00ff00ff00ffull & nValue);
    nValue = ((0xffff0000ffff0000ull & nValue)>>16) + (0x0000ffff0000ffffull & nValue);
    nValue = ((0xffffffff00000000ull & nValue)>>32) + (0x00000000ffffffffull & nValue);
	return nValue;
}
long long pow(long long n, long long m, long long mod = 0){
	long long ans = 1;
	long long k = n;
	while(m){
		if(m & 1) {
			ans *= k;
			if(mod) ans %= mod;
		}
		k *= k;
		if(mod) k %= mod;
		m >>= 1;
	}
	return ans;
}

const int maxn = 100100;
int n;
int arr[maxn], st[maxn], lst;

int main(){
//	freopen("input.txt","r", stdin);
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", arr + i);
	int ans = 0;
	for (int i = 0; i < n; ++i) ans = max1(ans, arr[i]);
	for(int j = 0; j < n; j++){
		while(lst && st[lst - 1] < arr[j]){
			ans = max1(arr[j] ^ st[lst - 1], ans);
			lst--;
		}
		st[lst++] = arr[j];
	}
	lst = 0;
	for(int j = n - 1; j >= 0; j--){
		while(lst && st[lst - 1] < arr[j]){
			ans = max1(arr[j] ^ st[lst - 1], ans);
			lst--;
		}
		st[lst++] = arr[j];
	}
	cout << ans << endl;

	return 0;
}


#include <iostream>
#include <algorithm>
#define DN 100005
using namespace std;

int n,v[DN],st[DN],sz,rez;

int main()
{
    cin>>n;
    for(int i=0; i<n; ++i) cin>>v[i];
    for(int i=0; i<n; ++i) {
      //cout<<v[i]<<' '<<st[sz]<<'\n';
      for(;sz>1 && st[sz]<v[i];--sz);
      st[++sz]=v[i];
      rez=max(rez,st[1]^st[2]);
    }
    reverse(v,v+n);sz=0;
    for(int i=0; i<n; ++i) {
      //cout<<v[i]<<' '<<st[sz]<<'\n';
      for(;sz>1 && st[sz]<v[i];--sz);
      st[++sz]=v[i];
      rez=max(rez,st[1]^st[2]);
    }
    cout<<rez;
    return 0;
}


#include <iostream>
#define DN 100005
using namespace std;

int n,v[DN],st[DN],sz,rez;

int main()
{
    cin>>n;
    for(int i=0; i<n; ++i) cin>>v[i];
    for(int i=0; i<n; ++i) {
      if(sz) rez=max(rez,v[i]^st[sz]);
      for(;sz && st[sz]<v[i];--sz);
      st[++sz]=v[i];
    }
    cout<<rez;
    return 0;
}


#include <iostream>
#include <algorithm>
#define DN 100005
using namespace std;

int n,v[DN],st[DN],sz,rez;

int main()
{
    cin>>n;
    for(int i=0; i<n; ++i) cin>>v[i];
    for(int i=0; i<n; ++i) {
      for(;sz && st[sz]<v[i];--sz);
      if(sz) rez=max(rez,v[i]^st[sz]);
     // cout<<v[i]<<' '<<st[sz]<<'\n';
      st[++sz]=v[i];
    }
    reverse(v,v+n);sz=0;
    for(int i=0; i<n; ++i) {
      for(;sz && st[sz]<v[i];--sz);
      if(sz) rez=max(rez,v[i]^st[sz]);
      st[++sz]=v[i];
    }
    cout<<rez;
    return 0;
}


#include <iostream>
#include <algorithm>
#define DN 100005
using namespace std;

int n,v[DN],st[DN],sz,rez;

int main()
{
    cin>>n;
    for(int i=0; i<n; ++i) cin>>v[i];
    for(int i=0; i<n; ++i) {
      //cout<<v[i]<<' '<<st[sz]<<'\n';
      if(sz) rez=max(rez,v[i]^st[1]);
      for(;sz && st[sz]<v[i];--sz);
      st[++sz]=v[i];
    }
    reverse(v,v+n);sz=0;
    for(int i=0; i<n; ++i) {
      //cout<<v[i]<<' '<<st[sz]<<'\n';
      if(sz) rez=max(rez,v[i]^st[1]);
      for(;sz && st[sz]<v[i];--sz);
      st[++sz]=v[i];
    }
    cout<<rez;
    return 0;
}


/*lcf*/

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<cmath>

#define FO(i,s,e,p) for(int i=(s);i<int(e);i+=p)
#define FOD(i,s,e,p) for(int i=(s);i>int(e);i-=p)

#define FOR(i,s,e) FO(i,s,e,1)
#define FORE(i,s,e) FOR(i,s,e+1)
#define FORD(i,s,e) FOD(i,s,e,1)
#define FORDE(i,s,e) FORD(i,s,e-1)

#define ALL(i,s) for(__typeof((s).begin()) i=(s).begin();i!=(s).end();i++)

#define MEM(tab,fill) memset(tab,fill,sizeof(tab))

#include<iostream>
#include<set>
#include<vector>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<algorithm>
#include<utility>
#include<bitset>
#include<map>
#include<cassert>
#define pb push_back
#define ll long long
using namespace std;

#define EPS 0.0000001
#define MOD 1000000007
#define mp make_pair
#define fi first
#define se second
#define inf (1<<29)
#define deb(a) cout<<#a<<' '<<a<<endl;

struct node{
    node *a[2];
    int cc;
    int val;
    node(){
        a[0]=a[1]=NULL;
        cc=0;
    }
};

void rem(node &on,int dep,int num){
     on.cc--;
     if(dep==-1) return;

     bool ox=((num&(1<<dep))!=0);
     rem(*on.a[ox],dep-1,num);
}
void put(node &on,int dep,int num){
     on.cc++;
     if(dep==-1) {on.val=num;return;}

     bool ox=((num&(1<<dep))!=0);

    if(on.a[ox]==NULL) on.a[ox]=new node();
    put(*on.a[ox],dep-1,num);

}
int get(node &on,int dep,int num,bool equal=1){
    if(dep==-1) return on.val;

    bool ox=((num&(1<<dep))!=0);
    if(equal){

        FORDE(i,ox,0){
            if(on.a[i]!=NULL && on.a[i]->cc){
                int rr=get(*on.a[i],dep-1,num,i==ox);
                if(rr!=-1) return rr;
            }
        }
        return -1;
    }else{
        FORDE(i,1,0){
            if(on.a[i]!=NULL && on.a[i]->cc){
                int rr=get(*on.a[i],dep-1,num,0);
                if(rr!=-1) return rr;
            }
        }
        return -1;
    }

}

node *rot;

#define LIM 30
int solve(vector<int> in){
    rot=new node();
    vector<int> xx;
    xx.pb(in[0]);put(*rot,LIM,in[0]);
    int ret=0;
    FOR(i,1,in.size()){
        if(rot->cc!=0) {
            int z=get(*rot,LIM,in[i]);
            if(z!=-1) ret=max(ret,z^in[i]);
        }

        while(xx.size() && xx.back()<in[i]){
            rem(*rot,LIM,xx.back());
            xx.pop_back();
        }
        if(xx.size()==0 || xx.back()<in[i]) put(*rot,LIM,in[i]);
    }

    return ret;
}

int main()
{
   // freopen("C:\\a","r",stdin);
    int n;cin>>n;
    vector<int> in(n);
    FOR(i,0,n) cin>>in[i];
    int a=solve(in);
    reverse(in.begin(),in.end());
    int b=solve(in);
    cout<<max(a,b);

    return 0;
}


/*lcf*/

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<cmath>

#define FO(i,s,e,p) for(int i=(s);i<int(e);i+=p)
#define FOD(i,s,e,p) for(int i=(s);i>int(e);i-=p)

#define FOR(i,s,e) FO(i,s,e,1)
#define FORE(i,s,e) FOR(i,s,e+1)
#define FORD(i,s,e) FOD(i,s,e,1)
#define FORDE(i,s,e) FORD(i,s,e-1)

#define ALL(i,s) for(__typeof((s).begin()) i=(s).begin();i!=(s).end();i++)

#define MEM(tab,fill) memset(tab,fill,sizeof(tab))

#include<iostream>
#include<set>
#include<vector>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<algorithm>
#include<utility>
#include<bitset>
#include<map>
#include<cassert>
#define pb push_back
#define ll long long
using namespace std;

#define EPS 0.0000001
#define MOD 1000000007
#define mp make_pair
#define fi first
#define se second
#define inf (1<<29)
#define deb(a) cout<<#a<<' '<<a<<endl;

struct node{
    node *a[2];
    int cc;
    int val;
    node(){
        a[0]=a[1]=NULL;
        cc=0;
    }
};

void rem(node &on,int dep,int num){
     on.cc--;
     if(dep==-1) return;

     bool ox=((num&(1<<dep))!=0);
     rem(*on.a[ox],dep-1,num);
}
void put(node &on,int dep,int num){
     on.cc++;
     if(dep==-1) {on.val=num;return;}

     bool ox=((num&(1<<dep))!=0);

    if(on.a[ox]==NULL) on.a[ox]=new node();
    put(*on.a[ox],dep-1,num);

}
int get(node &on,int dep,int num,bool equal=1){
    if(dep==-1) return on.val;

    bool ox=((num&(1<<dep))!=0);
    if(equal){

        FORDE(i,ox,0){
            if(on.a[i]!=NULL){
                int rr=get(*on.a[i],dep-1,num,i==ox);
                if(rr!=-1) return rr;
            }
        }
        return -1;
    }else{
        FORDE(i,1,0){
            if(on.a[i]!=NULL){
                int rr=get(*on.a[i],dep-1,num,0);
                if(rr!=-1) return rr;
            }
        }
        return -1;
    }

}

node *rot;

#define LIM 30
int solve(vector<int> in){
    rot=new node();
    vector<int> xx;
    xx.pb(in[0]);put(*rot,LIM,in[0]);
    int ret=0;
    FOR(i,1,in.size()){
        if(rot->cc!=0) {
            int z=get(*rot,LIM,in[i]);
            if(z!=-1) ret=max(ret,z^in[i]);
        }

        while(xx.size() && xx.back()<in[i]){
            rem(*rot,LIM,xx.back());
            xx.pop_back();
        }
        if(xx.size()==0 || xx.back()<in[i]) put(*rot,LIM,in[i]);
    }

    return ret;
}

int main()
{
   // freopen("C:\\a","r",stdin);
    int n;cin>>n;
    vector<int> in(n);
    FOR(i,0,n) cin>>in[i];
    int a=solve(in);
    reverse(in.begin(),in.end());
    int b=solve(in);
    cout<<max(a,b);

    return 0;
}


/*lcf*/

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<cmath>

#define FO(i,s,e,p) for(int i=(s);i<int(e);i+=p)
#define FOD(i,s,e,p) for(int i=(s);i>int(e);i-=p)

#define FOR(i,s,e) FO(i,s,e,1)
#define FORE(i,s,e) FOR(i,s,e+1)
#define FORD(i,s,e) FOD(i,s,e,1)
#define FORDE(i,s,e) FORD(i,s,e-1)

#define ALL(i,s) for(__typeof((s).begin()) i=(s).begin();i!=(s).end();i++)

#define MEM(tab,fill) memset(tab,fill,sizeof(tab))

#include<iostream>
#include<set>
#include<vector>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<algorithm>
#include<utility>
#include<bitset>
#include<map>
#include<cassert>
#define pb push_back
#define ll long long
using namespace std;

#define EPS 0.0000001
#define MOD 1000000007
#define mp make_pair
#define fi first
#define se second
#define inf (1<<29)
#define deb(a) cout<<#a<<' '<<a<<endl;

struct node{
    node *a[2];
    int cc;
    int val;
    node(){
        val=-1;
        a[0]=a[1]=NULL;
        cc=0;
    }
};

void rem(node &on,int dep,int num){
     on.cc--;
     if(dep==-1) {on.val=-1;return;}

     bool ox=((num&(1<<dep))!=0);
     rem(*on.a[ox],dep-1,num);
}
void put(node &on,int dep,int num){
     on.cc++;
     if(dep==-1) {on.val=num;return;}

     bool ox=((num&(1<<dep))!=0);

    if(on.a[ox]==NULL) on.a[ox]=new node();
    put(*on.a[ox],dep-1,num);

}
bool chk(node *on){
    if(on==NULL) return 0;
    if(on->cc==0) return 0;
    return 1;

}

int ar[2][2]={1,0,0,1};

int get(node &on,int dep,int num,bool equal){
    if(dep==-1) {return on.val;}

    bool ox=((num&(1<<dep))!=0);
    if(equal){
        FOR(x,0,2){
            int i=ar[ox][x];
            if(i>ox) continue;
            if(!chk(on.a[i])) continue;
            int rr=get(*on.a[i],dep-1,num,i==ox);
            if(rr!=-1) return rr;
        }

        return -1;
    }else{
        FOR(x,0,2){
            int i=ar[ox][x];
            if(!chk(on.a[i])) continue;
            int rr=get(*on.a[i],dep-1,num,0);
            if(rr!=-1) return rr;
        }

        return -1;
    }
  //  assert(0);

}

node *rot;

#define LIM 30
int solve(vector<int> in){
    rot=new node();
    vector<int> xx;
    xx.pb(in[0]);put(*rot,LIM,in[0]);
    int ret=0;
    FOR(i,1,in.size()){

        int z=get(*rot,LIM,in[i],1);
        if(z!=-1) ret=max(ret,z^in[i]);

        while(xx.size() && xx.back()<in[i]){
            rem(*rot,LIM,xx.back());
            xx.pop_back();
        }
        if(xx.size()==0 || xx.back()<in[i]) put(*rot,LIM,in[i]);
    }

    return ret;
}

int main()
{
    //freopen("C:\\a","r",stdin);

    int n;cin>>n;
    vector<int> in(n);
    FOR(i,0,n) cin>>in[i];
    int a=solve(in);
    reverse(in.begin(),in.end());
    int b=solve(in);
    cout<<max(a,b);

    return 0;
}


/*lcf*/

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<cmath>

#define FO(i,s,e,p) for(int i=(s);i<int(e);i+=p)
#define FOD(i,s,e,p) for(int i=(s);i>int(e);i-=p)

#define FOR(i,s,e) FO(i,s,e,1)
#define FORE(i,s,e) FOR(i,s,e+1)
#define FORD(i,s,e) FOD(i,s,e,1)
#define FORDE(i,s,e) FORD(i,s,e-1)

#define ALL(i,s) for(__typeof((s).begin()) i=(s).begin();i!=(s).end();i++)

#define MEM(tab,fill) memset(tab,fill,sizeof(tab))

#include<iostream>
#include<set>
#include<vector>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<algorithm>
#include<utility>
#include<bitset>
#include<map>
#include<cassert>
#define pb push_back
#define ll long long
using namespace std;

#define EPS 0.0000001
#define MOD 1000000007
#define mp make_pair
#define fi first
#define se second
#define inf (1<<29)
#define deb(a) cout<<#a<<' '<<a<<endl;

struct node{
    node *a[2];
    int cc;
    int val;
    node(){
        val=-1;
        a[0]=a[1]=NULL;
        cc=0;
    }
};

void rem(node &on,int dep,int num){
     on.cc--;
     if(dep==-1) {on.val=-1;return;}

     bool ox=((num&(1<<dep))!=0);
     rem(*on.a[ox],dep-1,num);
}
void put(node &on,int dep,int num){
     on.cc++;
     if(dep==-1) {on.val=num;return;}

     bool ox=((num&(1<<dep))!=0);

    if(on.a[ox]==NULL) on.a[ox]=new node();
    put(*on.a[ox],dep-1,num);

}
int get(node &on,int dep,int num,bool equal){
    if(dep==-1) {assert(on.val!=-1);return on.val;}

    bool ox=((num&(1<<dep))!=0);
    if(equal){

        FORDE(i,ox,0){
            if(on.a[i]!=NULL && on.a[i]->cc){
                int rr=get(*on.a[i],dep-1,num,i==ox);
                if(rr!=-1) return rr;
            }
        }
        return -1;
    }else{
        FORDE(i,1,0){
            if(on.a[i]!=NULL && on.a[i]->cc){
                int rr=get(*on.a[i],dep-1,num,0);
                if(rr!=-1) return rr;
            }
        }
        return -1;
    }
    assert(0);

}

node *rot;

#define LIM 30
int solve(vector<int> in){
    rot=new node();
    vector<int> xx;
    xx.pb(in[0]);put(*rot,LIM,in[0]);
    int ret=0;
    FOR(i,1,in.size()){

        int z=get(*rot,LIM,in[i],1);
        if(z!=-1) ret=max(ret,z^in[i]);

        while(xx.size() && xx.back()<in[i]){
            rem(*rot,LIM,xx.back());
            xx.pop_back();
        }
        if(xx.size()==0 || xx.back()<in[i]) put(*rot,LIM,in[i]);
    }

    return ret;
}

int main()
{
    //freopen("C:\\a","r",stdin);

    int n;cin>>n;
    vector<int> in(n);
    FOR(i,0,n) cin>>in[i];
    int a=solve(in);
    reverse(in.begin(),in.end());
    int b=solve(in);
    cout<<max(a,b);

    return 0;
}


/*lcf*/

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<cmath>

#define FO(i,s,e,p) for(int i=(s);i<int(e);i+=p)
#define FOD(i,s,e,p) for(int i=(s);i>int(e);i-=p)

#define FOR(i,s,e) FO(i,s,e,1)
#define FORE(i,s,e) FOR(i,s,e+1)
#define FORD(i,s,e) FOD(i,s,e,1)
#define FORDE(i,s,e) FORD(i,s,e-1)

#define ALL(i,s) for(__typeof((s).begin()) i=(s).begin();i!=(s).end();i++)

#define MEM(tab,fill) memset(tab,fill,sizeof(tab))

#include<iostream>
#include<set>
#include<vector>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<algorithm>
#include<utility>
#include<bitset>
#include<map>
#include<cassert>
#define pb push_back
#define ll long long
using namespace std;

#define EPS 0.0000001
#define MOD 1000000007
#define mp make_pair
#define fi first
#define se second
#define inf (1<<29)
#define deb(a) cout<<#a<<' '<<a<<endl;

struct node{
    node *a[2];
    int cc;
    int val;
    node(){
        val=-1;
        a[0]=a[1]=NULL;
        cc=0;
    }
};

void rem(node &on,int dep,int num){
     on.cc--;
     if(dep==-1) {on.val=-1;return;}

     bool ox=((num&(1<<dep))!=0);
     rem(*on.a[ox],dep-1,num);
}
void put(node &on,int dep,int num){
     on.cc++;
     if(dep==-1) {on.val=num;return;}

     bool ox=((num&(1<<dep))!=0);

    if(on.a[ox]==NULL) on.a[ox]=new node();
    put(*on.a[ox],dep-1,num);

}
bool chk(node *on){
    if(on==NULL) return 0;
    if(on->cc==0) return 0;
    return 1;

}

int ar[2][2]={1,0,0,1};

int get(node &on,int dep,int num,bool equal){
    if(dep==-1) {assert(on.val!=-1);return on.val;}

    bool ox=((num&(1<<dep))!=0);
    if(equal){
        FOR(x,0,2){
            int i=ar[ox][x];
            if(i>ox) continue;
            if(!chk(on.a[i])) continue;
            int rr=get(*on.a[i],dep-1,num,i==ox);
            if(rr!=-1) return rr;
        }

        return -1;
    }else{
        FOR(x,0,2){
            int i=ar[ox][x];
            if(!chk(on.a[i])) continue;
            int rr=get(*on.a[i],dep-1,num,0);
            if(rr!=-1) return rr;
        }

        return -1;
    }

}

node *rot;

#define LIM 30
int solve(vector<int> in){
    rot=new node();
    vector<int> xx;
    xx.pb(in[0]);put(*rot,LIM,in[0]);
    int ret=0;
    FOR(i,1,in.size()){

        int z=get(*rot,LIM,in[i],1);
        if(z!=-1) ret=max(ret,z^in[i]);

        while(xx.size() && xx.back()<in[i]){
            rem(*rot,LIM,xx.back());
            xx.pop_back();
        }
        if(xx.size()==0 || xx.back()<in[i]) put(*rot,LIM,in[i]);
    }

    return ret;
}

int main()
{
    //freopen("C:\\a","r",stdin);

    int n;cin>>n;
    vector<int> in(n);
    FOR(i,0,n) cin>>in[i];
    int a=solve(in);
    reverse(in.begin(),in.end());
    int b=solve(in);
    cout<<max(a,b);

    return 0;
}


/*lcf*/

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<cmath>

#define FO(i,s,e,p) for(int i=(s);i<int(e);i+=p)
#define FOD(i,s,e,p) for(int i=(s);i>int(e);i-=p)

#define FOR(i,s,e) FO(i,s,e,1)
#define FORE(i,s,e) FOR(i,s,e+1)
#define FORD(i,s,e) FOD(i,s,e,1)
#define FORDE(i,s,e) FORD(i,s,e-1)

#define ALL(i,s) for(__typeof((s).begin()) i=(s).begin();i!=(s).end();i++)

#define MEM(tab,fill) memset(tab,fill,sizeof(tab))

#include<iostream>
#include<set>
#include<vector>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<algorithm>
#include<utility>
#include<bitset>
#include<map>
#include<cassert>
#define pb push_back
#define ll long long
using namespace std;

#define EPS 0.0000001
#define MOD 1000000007
#define mp make_pair
#define fi first
#define se second
#define inf (1<<29)
#define deb(a) cout<<#a<<' '<<a<<endl;

struct node{
    node *a[2];
    int cc;
    int val;
    node(){
        val=-1;
        a[0]=a[1]=NULL;
        cc=0;
    }
};

void rem(node &on,int dep,int num){
     on.cc--;
     if(dep==-1) {on.val=-1;return;}

     bool ox=((num&(1<<dep))!=0);
     rem(*on.a[ox],dep-1,num);
}
void put(node &on,int dep,int num){
     on.cc++;
     if(dep==-1) {on.val=num;return;}

     bool ox=((num&(1<<dep))!=0);

    if(on.a[ox]==NULL) on.a[ox]=new node();
    put(*on.a[ox],dep-1,num);

}
bool chk(node *on){
    if(on==NULL) return 0;
    if(on->cc==0) return 0;
    return 1;

}

int ar[2][2]={1,0,0,1};

int get(node &on,int dep,int num,bool equal){
    if(equal==1 && dep==-1) assert(0);
    if(dep==-1) {assert(on.val!=-1);return on.val;}

    bool ox=((num&(1<<dep))!=0);
    if(equal){
        FOR(x,0,2){
            int i=ar[ox][x];
            if(i>ox) continue;
            if(!chk(on.a[i])) continue;
            int rr=get(*on.a[i],dep-1,num,i==ox);
            if(rr!=-1) return rr;
        }

        return -1;
    }else{
        FOR(x,0,2){
            int i=ar[ox][x];
            if(!chk(on.a[i])) continue;
            int rr=get(*on.a[i],dep-1,num,0);
            if(rr!=-1) return rr;
        }

        return -1;
    }

}

node *rot;

#define LIM 30
int solve(vector<int> in){
    rot=new node();
    vector<int> xx;
    xx.pb(in[0]);put(*rot,LIM,in[0]);
    int ret=0;
    FOR(i,1,in.size()){

        int z=get(*rot,LIM,in[i],1);
        if(z!=-1) ret=max(ret,z^in[i]);

        while(xx.size() && xx.back()<in[i]){
            rem(*rot,LIM,xx.back());
            xx.pop_back();
        }
        if(xx.size()==0 || xx.back()<in[i]) put(*rot,LIM,in[i]);
    }

    return ret;
}

int main()
{
    //freopen("C:\\a","r",stdin);

    int n;cin>>n;
    vector<int> in(n);
    FOR(i,0,n) cin>>in[i];
    int a=solve(in);
    reverse(in.begin(),in.end());
    int b=solve(in);
    cout<<max(a,b);

    return 0;
}


/*lcf*/

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<cmath>

#define FO(i,s,e,p) for(int i=(s);i<int(e);i+=p)
#define FOD(i,s,e,p) for(int i=(s);i>int(e);i-=p)

#define FOR(i,s,e) FO(i,s,e,1)
#define FORE(i,s,e) FOR(i,s,e+1)
#define FORD(i,s,e) FOD(i,s,e,1)
#define FORDE(i,s,e) FORD(i,s,e-1)

#define ALL(i,s) for(__typeof((s).begin()) i=(s).begin();i!=(s).end();i++)

#define MEM(tab,fill) memset(tab,fill,sizeof(tab))

#include<iostream>
#include<set>
#include<vector>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<algorithm>
#include<utility>
#include<bitset>
#include<map>
#include<cassert>
#define pb push_back
#define ll long long
using namespace std;

#define EPS 0.0000001
#define MOD 1000000007
#define mp make_pair
#define fi first
#define se second
#define inf (1<<29)
#define deb(a) cout<<#a<<' '<<a<<endl;

struct node{
    node *a[2];
    int cc;
    int val;
    node(){
        val=-1;
        a[0]=a[1]=NULL;
        cc=0;
    }
};

void rem(node &on,int dep,int num){
     on.cc--;
     if(dep==-1) {on.val=-1;return;}

     bool ox=((num&(1<<dep))!=0);
     rem(*on.a[ox],dep-1,num);
}
void put(node &on,int dep,int num){
     on.cc++;
     if(dep==-1) {on.val=num;return;}

     bool ox=((num&(1<<dep))!=0);

    if(on.a[ox]==NULL) on.a[ox]=new node();
    put(*on.a[ox],dep-1,num);

}
bool chk(node *on){
    if(on==NULL) return 0;
    if(on->cc==0) return 0;
    return 1;

}

int ar[2][2]={1,0,0,1};

int get(node &on,int dep,int num,bool equal){
    if(equal==1 && dep==-1) assert(0);
    if(dep==-1) {assert(on.val!=-1);return on.val;}

    int ox=((num&(1<<dep))!=0);
    if(equal){
        FOR(x,0,2){
            int i=ar[ox][x];
            if(i>ox) continue;
            if(!chk(on.a[i])) continue;
            int rr=get(*on.a[i],dep-1,num,i==ox);
            if(rr!=-1) return rr;
        }

        return -1;
    }else{
        FOR(x,0,2){
            int i=ar[ox][x];
            if(!chk(on.a[i])) continue;
            int rr=get(*on.a[i],dep-1,num,0);
            if(rr!=-1) return rr;
        }

        return -1;
    }

}

node *rot;

#define LIM 30
int solve(vector<int> in){
    rot=new node();
    vector<int> xx;
    xx.pb(in[0]);put(*rot,LIM,in[0]);
    int ret=0;
    FOR(i,1,in.size()){

        int z=get(*rot,LIM,in[i],1);
        if(z!=-1) ret=max(ret,z^in[i]);

        while(xx.size() && xx.back()<in[i]){
            rem(*rot,LIM,xx.back());
            xx.pop_back();
        }
        if(xx.size()==0 || xx.back()>in[i]) put(*rot,LIM,in[i]),xx.pb(in[i]);
    }

    return ret;
}

int main()
{
    //freopen("C:\\a","r",stdin);

    int n;cin>>n;
    vector<int> in(n);
    FOR(i,0,n) cin>>in[i];
    int a=solve(in);
    reverse(in.begin(),in.end());
    int b=solve(in);
    cout<<max(a,b);

    return 0;
}


/*lcf*/

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<cmath>

#define FO(i,s,e,p) for(int i=(s);i<int(e);i+=p)
#define FOD(i,s,e,p) for(int i=(s);i>int(e);i-=p)

#define FOR(i,s,e) FO(i,s,e,1)
#define FORE(i,s,e) FOR(i,s,e+1)
#define FORD(i,s,e) FOD(i,s,e,1)
#define FORDE(i,s,e) FORD(i,s,e-1)

#define ALL(i,s) for(__typeof((s).begin()) i=(s).begin();i!=(s).end();i++)

#define MEM(tab,fill) memset(tab,fill,sizeof(tab))

#include<iostream>
#include<set>
#include<vector>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<algorithm>
#include<utility>
#include<bitset>
#include<map>
#include<cassert>
#define pb push_back
#define ll long long
using namespace std;

#define EPS 0.0000001
#define MOD 1000000007
#define mp make_pair
#define fi first
#define se second
#define inf (1<<29)
#define deb(a) cout<<#a<<' '<<a<<endl;

struct node{
    node *a[2];
    int cc;
    int val;
    node(){
        val=-1;
        a[0]=a[1]=NULL;
        cc=0;
    }
};

void rem(node &on,int dep,int num){
     on.cc--;
     if(dep==-1) {on.val=-1;return;}

     bool ox=((num&(1<<dep))!=0);
     rem(*on.a[ox],dep-1,num);
}
void put(node &on,int dep,int num){
     on.cc++;
     if(dep==-1) {on.val=num;return;}

     bool ox=((num&(1<<dep))!=0);

    if(on.a[ox]==NULL) on.a[ox]=new node();
    put(*on.a[ox],dep-1,num);

}
bool chk(node *on){
    if(on==NULL) return 0;
    if(on->cc==0) return 0;
    return 1;

}

int ar[2][2]={1,0,0,1};

int get(node &on,int dep,int num,bool equal){
    if(dep==-1) {assert(on.val!=-1);return on.val;}

    bool ox=((num&(1<<dep))!=0);
    if(equal){
        FOR(x,0,2){
            int i=ar[ox][x];
            if(i>ox) continue;
            if(!chk(on.a[i])) continue;
            int rr=get(*on.a[i],dep-1,num,i==ox);
            if(rr!=-1) return rr;
        }

        return -1;
    }else{
        FOR(x,0,2){
            int i=ar[ox][x];
            if(!chk(on.a[i])) continue;
            int rr=get(*on.a[i],dep-1,num,0);
            if(rr!=-1) return rr;
        }

        return -1;
    }
    assert(0);

}

node *rot;

#define LIM 30
int solve(vector<int> in){
    rot=new node();
    vector<int> xx;
    xx.pb(in[0]);put(*rot,LIM,in[0]);
    int ret=0;
    FOR(i,1,in.size()){

        int z=get(*rot,LIM,in[i],1);
        if(z!=-1) ret=max(ret,z^in[i]);

        while(xx.size() && xx.back()<in[i]){
            rem(*rot,LIM,xx.back());
            xx.pop_back();
        }
        if(xx.size()==0 || xx.back()<in[i]) put(*rot,LIM,in[i]);
    }

    return ret;
}

int main()
{
    freopen("C:\\a","r",stdin);

    int n;cin>>n;
    vector<int> in(n);
    FOR(i,0,n) cin>>in[i];
    int a=solve(in);
    reverse(in.begin(),in.end());
    int b=solve(in);
    cout<<max(a,b);

    return 0;
}


#include <sstream>
#include <fstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

/*
5
5 2 1 4 3
*/

int n;
int a[100050];

int main() {
	//ifstream in( "in.txt" );
	istream& in = cin;

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

	// �e�r�b�g�̏o�������擾
	int bits[30]; memset( bits, 0, sizeof(bits) );
	for( int i = 0; i < 30; i++ ){
		int b = 1 << i;
		for( int j = 0; j < n; j++ ){
			bits[i] += ((a[j] & b) != 0);
		}
	}

	int m = 0;
	int msb = 0;
	for( int i = 29; i >= 0; i-- ){
		if( bits[i] == n ){
			m |= (1 << i);
		}else if( bits[i] != 0 ){
			msb = 1 << i;
			break;
		}
	}

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

	int res = 0;
	for( int i = 0; i < n; ){
		if( a[i] & msb ){
			int first = a[i];
			// ��������O�𒲂ׂ�
			int j = i - 1;
			int second = 0;
			for( ; j >= 0 && (a[j] & msb) == 0; j-- ){
				if( a[j] >= second ){
					second = a[j];
					res = max( res, first ^ second );
				}
			}
			// ����������𒲂ׂ�
			j = i + 1;
			second = 0;
			for( ; j < n && (a[j] & msb) == 0; j++ ){
				if( a[j] >= second ){
					second = a[j];
					res = max( res, first ^ second );
				}
			}
			i = j;
		}else{
			i++;
		}
	}

	cout << res << endl;

//	while( true ){}
}


#include <sstream>
#include <fstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

/*
5
5 2 1 4 3
*/

int n;
int a[100050];

int main() {
	//ifstream in( "in.txt" );
	istream& in = cin;

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

	// msb���擾
	int msb = 1;
	for( int i = 0; i < n; i++ ){
		while( msb * 2 <= a[i] ){
			msb *= 2;
		}
	}

	int res = 0;
	for( int i = 0; i < n; ){
		if( a[i] & msb ){
			int first = a[i];
			// ��������O�𒲂ׂ�
			int j = i - 1;
			int second = 0;
			for( ; j >= 0 && (a[j] & msb) == 0; j-- ){
				if( a[j] > second ){
					second = a[j];
					res = max( res, first ^ second );
				}
			}
			// ����������𒲂ׂ�
			j = i + 1;
			second = 0;
			for( ; j < n && (a[j] & msb) == 0; j++ ){
				if( a[j] > second ){
					second = a[j];
					res = max( res, first ^ second );
				}
			}
			// msb���m�ł�����Ă���
			if( j < n ){
				res = max( res, first ^ a[j] );
			}
			i = j;
		}else{
			i++;
		}
	}

	cout << res << endl;

//	while( true ){}
}


#include <sstream>
#include <fstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

/*
5
5 2 1 4 3
*/

int n;
int a[100050];

int main() {
	//ifstream in( "in.txt" );
	istream& in = cin;

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

	// �e�r�b�g�̏o�������擾
	int bits[30]; memset( bits, 0, sizeof(bits) );
	for( int i = 0; i < 30; i++ ){
		int b = 1 << i;
		for( int j = 0; j < n; j++ ){
			bits[i] += ((a[j] & b) != 0);
		}
	}

	int m = 0;
	int msb = 0;
	for( int i = 29; i >= 0; i-- ){
		if( bits[i] == n ){
			m |= (1 << i);
		}else if( bits[i] != 0 ){
			msb = 1 << i;
			break;
		}
	}

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

	int res = 0;
	for( int i = 0; i < n; ){
		if( a[i] & msb ){
			int first = a[i];
			// ��������O�𒲂ׂ�
			int j = i - 1;
			int second = 0;
			for( ; j >= 0 && (a[j] & msb) == 0; j-- ){
				if( a[j] > second ){
					second = a[j];
					res = max( res, first ^ second );
				}
			}
			// ����������𒲂ׂ�
			j = i + 1;
			second = 0;
			for( ; j < n && (a[j] & msb) == 0; j++ ){
				if( a[j] > second ){
					second = a[j];
					res = max( res, first ^ second );
				}
			}
			i = j;
		}else{
			i++;
		}
	}

	cout << res << endl;

//	while( true ){}
}


#include <sstream>
#include <fstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

/*
5
5 2 1 4 3
*/

int n;
int a[100050];

int main() {
	//ifstream in( "in.txt" );
	istream& in = cin;

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

	// msb���擾
	int msb = 1;
	for( int i = 0; i < n; i++ ){
		while( msb * 2 <= a[i] ){
			msb *= 2;
		}
	}

	int res = 0;
	for( int i = 0; i < n; ){
		if( a[i] & msb ){
			int first = a[i];
			// ��������O�𒲂ׂ�
			int j = i - 1;
			int second = 0;
			for( ; j >= 0 && (a[j] & msb) == 0; j-- ){
				if( a[j] > second ){
					second = a[j];
					res = max( res, first ^ second );
				}
			}
			// ����������𒲂ׂ�
			j = i + 1;
			second = 0;
			for( ; j < n && (a[j] & msb) == 0; j++ ){
				if( a[j] > second ){
					second = a[j];
					res = max( res, first ^ second );
				}
			}
			// msb���m�ł�����Ă���
			if( j < n ){
				res = max( first, a[j] );
			}
			i = j;
		}else{
			i++;
		}
	}

	cout << res << endl;

//	while( true ){}
}


#include <sstream>
#include <fstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

/*
5
5 2 1 4 3
*/

int n;
int a[100050];

int main() {
	//ifstream in( "in.txt" );
	istream& in = cin;

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

	// msb���擾
	int msb = 1;
	for( int i = 0; i < n; i++ ){
		while( msb * 2 <= a[i] ){
			msb *= 2;
		}
	}

	int res = 0;
	for( int i = 0; i < n; ){
		if( a[i] & msb ){
			int first = a[i];
			// ��������O�𒲂ׂ�
			int j = i - 1;
			int second = 0;
			for( ; j >= 0 && (a[j] & msb) == 0; j-- ){
				if( a[j] > second ){
					second = a[j];
					res = max( res, first ^ second );
				}
			}
			// ����������𒲂ׂ�
			j = i + 1;
			second = 0;
			for( ; j < n && (a[j] & msb) == 0; j++ ){
				if( a[j] > second ){
					second = a[j];
					res = max( res, first ^ second );
				}
			}
			i = j;
		}else{
			i++;
		}
	}

	cout << res << endl;

//	while( true ){}
}


#include <sstream>
#include <fstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

int main() {

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

	bool win[301][301];
	memset( win, false, sizeof(win) );
	for( int i = 0; i <= 300; i++ ){
		for( int j = 0; j <= 300; j++ ){
			bool ok = false;
			// i���P�����炵���̂����Ă���
			for( int t = i - 1; t >= 0; t-- ){
				if( !win[t][j] ) ok = true;
			}
			// j���P�����炵���̂����Ă���
			for( int t = j - 1; t >= 0; t-- ){
				if( !win[i][t] ) ok = true;
			}
			// ����炵���̂����Ă���
			for( int t = min(i,j); t >= 1; t-- ){
				if( !win[i-t][j-t] ) ok = true;
			}
			if( ok ) win[i][j] = true;
		}
	}

	if( n == 1 ){
		if( a[1] != 0 ){
			cout <<  "BitLGM" << endl;
		}else{
			cout <<  "BitAryo" << endl;
		}
	}

	if( n == 2 ){
		if( win[a[1]][a[2]] ){
			cout <<  "BitLGM" << endl;
		}else{
			cout <<  "BitAryo" << endl;
		}
	}

	if( n == 3 ){
		int x = a[1] ^ a[2] ^ a[3];
		if( x != 0 ){
			cout <<  "BitLGM" << endl;
		}else{
			cout <<  "BitAryo" << endl;
		}
	}
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
#define REP(i,n) FOR(i,1,(n)+1)
typedef vector<int> vi;
#define pb push_back
typedef pair<int,int> pii;
#define mp make_pair
#define st first
#define nd second
typedef long long ll;
#define INF 1000000001
#define sz size()
#define VAR(n,v) typeof(v) n=(v)
#define ALL(t) t.begin(),t.end()
#define SC(a) scanf("%d", &a)
#define GET(a) int a; SC(a)
#define ISDEBUG 0
#define dprintf(...) if(ISDEBUG) {printf("\033[31m"); printf(__VA_ARGS__); printf("\033[0m");}
template <class It> void dptab(It b, It e, const char* f="%d ") {if(ISDEBUG) {for(It it=b; it!=e; ++it) dprintf(f, *it); dprintf("\n"); }}

vi t,l,p;

int do_range(int a, int b) {
	if(b - a < 2) return 0;

	int k = a;
	while(p[k] && t[p[k]] > t[k])
		k = p[k];
	int mxor = 0;
	for(int i=k-1; t[i]; i=l[i])
		mxor = max(mxor, t[k]^t[i]);
	for(int i=k+1; t[i]; i=p[i])
		mxor = max(mxor, t[k]^t[i]);

	mxor = max(mxor, do_range(a,k-1));
	mxor = max(mxor, do_range(k+1,b));
	return mxor;
}

int main() {
	GET(n);
	t.resize(n+2,0), l.resize(n+1,0), p.resize(n+1,0);
	REP(i,n) SC(t[i]);
	REP(i,n) {
		int j = i-1;
		while(j && t[j]<t[i])
			j = l[j];
		l[i] = j;
	}
	for(int i=n; i; --i) {
		int j = i==n? 0 : i+1;
		while(j && t[i]>t[j])
			j = p[j];
		p[i] = j;
	}
	dptab(ALL(l));
	dptab(ALL(t));
	dptab(ALL(p));

	printf("%d\n", do_range(1,n));
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
#define REP(i,n) FOR(i,1,(n)+1)
typedef vector<int> vi;
#define pb push_back
typedef pair<int,int> pii;
#define mp make_pair
#define st first
#define nd second
typedef long long ll;
#define INF 1000000001
#define sz size()
#define VAR(n,v) typeof(v) n=(v)
#define ALL(t) t.begin(),t.end()
#define SC(a) scanf("%d", &a)
#define GET(a) int a; SC(a)
#define ISDEBUG 0
#define dprintf(...) if(ISDEBUG) {printf("\033[31m"); printf(__VA_ARGS__); printf("\033[0m");}
template <class It> void dptab(It b, It e, const char* f="%d ") {if(ISDEBUG) {for(It it=b; it!=e; ++it) dprintf(f, *it); dprintf("\n"); }}

vi t;

#define bit(i) (1<<(i))
#define isset(n,i) (n&bit(i))
#define cbi(n,i) n -= bit(i)

vector<bool> B;
int n;

bool roznicuj() {
	int mx=0;
	REP(i,n) mx=max(mx,t[i]);
	int mbit;
	for(int bi=0; bi<=30; ++bi)
		if(isset(mx,bi))
			mbit = bi;
	int cnt=0;
	REP(i,n)
		if(isset(t[i],mbit))
			++cnt;
	if(cnt == n) {
		REP(i,n) t[i] -= bit(mbit);
		return true;
	}
	REP(i,n)
		if(isset(t[i],mbit))
			B[i] = true;
	return false;
}

int main() {
	SC(n);
	t.resize(n+1,0);
	B.resize(n+1,false);
	REP(i,n) SC(t[i]);

	int mbit;
	while(roznicuj());

	int mxor = 0;
	REP(i,n) if(B[i]) {
		int maxt = 0;
		for(int j=i+1; j<=n && !B[j]; ++j)
			if(t[j] > maxt) {
				maxt = t[j];
				mxor = max(mxor, t[j]^t[i]);
			}
		maxt = 0;
		for(int j=i-1; j>0 && !B[j]; --j)
			if(t[j] > maxt) {
				maxt = t[j];
				mxor = max(mxor, t[j]^t[i]);
			}
	}

	printf("%d\n", mxor);
}