#include <bits/stdc++.h>

using namespace std;

#define ll long long
const int INF=1e9;
const ll LINF=1e18,MOD=1e9+7,LOG=17;
const int SQ=317;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define PRINT(x) cerr<<#x<<'='<<x<<endl;
#define pb push_back
#define PRINTvec(niz) {cerr<<#niz<<"="; for(auto _i:niz) cerr<<_i<<" "; cerr<<endl; }

void Md(ll& x){
    if(x>=MOD) x%=MOD;
}

void Solve(){
    int N,M; cin>>N>>M;
    vector<pii> adj[N+1];
    for(int i=0;i<M;i++){
        int u,v,t; cin>>u>>v>>t;
        adj[u].pb({v,t});
        adj[v].pb({u,t});
    }
    int U,V; cin>>U>>V;
    vector<vector<int>> dist(N+1,vector<int>(2,INF));
    vector<vector<bool>> visited(N+1,vector<bool>(2,false));

    function<int()> Dijkstra=[&](){
        priority_queue<pair<int,pii>,vector<pair<int,pii>>,greater<pair<int,pii>>> pq;
        pq.push({0,{U,0}});
        while(!pq.empty()){
            pair<int,pii> vrh=pq.top(); pq.pop();
            if(!visited[vrh.se.fi][vrh.se.se]){
                visited[vrh.se.fi][vrh.se.se]=true;
                dist[vrh.se.fi][vrh.se.se]=vrh.fi;
                int s=vrh.se.se;
                for(auto x:adj[vrh.se.fi]){
                    int ns=x.se;
                    int nxt=x.fi;
                    if(!visited[nxt][ns]) pq.push({dist[vrh.se.fi][vrh.se.se]+(s^ns),{nxt,ns}});
                }
            }
        }
        return min(dist[V][0],dist[V][1]);
    };
    cout<<Dijkstra()<<endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t; t=1;
    //cin>>t;;
    while(t--){
        Solve();
    }
    return 0;
}