#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const int N=50005;
const int M=200005;
ll getin(){
char c;bool flag=0;ll num=0ll;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=1;
while(c>='0'&&c<='9'){num=num*10+c-48;c=getchar();}
if(flag) num=-num;
return num;
}
int n,m,cnt=1,fir[N],tar[M],nxt[M];
ll w[M],f[N],a[65];bool dfn[N];
inline void link(int a,int b,ll c){
tar[++cnt]=b,w[cnt]=c;
nxt[cnt]=fir[a],fir[a]=cnt;
}
inline void insert(ll x){
for(int i=61;i>=0;i--)if(x&(1ll<<i)){
if(a[i]) x^=a[i];
else{a[i]=x;break ;}
}
}
void dfs(int x,int last){
dfn[x]=1;
for(int i=fir[x];i;i=nxt[i]){
if(i==(last^1)) continue ;
if(!dfn[tar[i]]){
f[tar[i]]=f[x]^w[i];
dfs(tar[i],i);
}
else insert(f[x]^f[tar[i]]^w[i]);
}
}
int main(){
n=getin(),m=getin();
while(m--){
int x=getin(),y=getin();
ll w=getin();
link(x,y,w),link(y,x,w);
}
dfs(1,0);
ll ans=f[n];
for(int i=61;i>=0;i--)
ans=max(ans,ans^a[i]);
cout<<ans<<endl;
}