#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<cctype>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define RepD(i,n) for(int i=n;i>=0;i--)
#define MEM(a) memset(a,0,sizeof(a))
#define MEMI(a) memset(a,127,sizeof(a))
#define MEMi(a) memset(a,128,sizeof(a))
#define MAXN (50000+10)
#define MAXM (2*100000+10)
int n,m;
int edge[MAXM],pre[MAXN]={0},next[MAXM]={0};
long long weight[MAXM],size=0;
void addedge(int u,int v,long long w)
{
edge[++size]=v;
weight[size]=w;
next[size]=pre[u];
pre[u]=size;
}
bool b[MAXN]={0};
long long d[MAXN]={0};
long long a[MAXN+MAXM],a_n=0;
void dfs(int x)
{
b[x]=1;
Forp(x)
{
int &v=edge[p];
if (!b[v])
{
d[v]=d[x]^weight[p];
dfs(v);
}else a[++a_n]=d[x]^d[v]^weight[p];
}
//b[x]=0;
}
int gauss_lb()
{
int k=1;
ForD(i,64)
{
int t=0;
Fork(j,k,a_n) if ((a[j]>>i-1)&1) t=j;
if (!t) continue;
swap(a[k],a[t]);
Fork(j,k+1,a_n) if ((a[j]>>i-1)&1) a[j]^=a[k];
k++;
}
return --k;
}
int main()
{
// freopen("bzoj2115.in","r",stdin);
// freopen(".out","w",stdout);
scanf("%d%d",&n,&m);
For(i,m)
{
int u,v;long long w;
cin>>u>>v>>w;
//cout<<u<<' '<<v<<' '<<w<<endl;
addedge(u,v,w);addedge(v,u,w);
}
dfs(1);
long long ans=d[n];
int tot=gauss_lb();
For(i,tot)
{
ans=max(ans,ans^a[i]);
}
cout<<ans<<endl;
return 0;
}