#include<iostream>
#include<queue>
#include<stack>
using namespace std;
const int N=1e5+5;
vector<pair<int,int> > g[N];
int pre[N],d[N];
bool vs[N];
int main(){
int n,m;
cin>>n>>m;
while(m--){
int u,v,w;
cin>>u>>v>>w;
g[u].push_back({v,w});
g[v].push_back({u,w});
}
for(int i=1;i<=n;i++) d[i] = 0x3f3f3f3f;
d[1] = 0;
priority_queue<pair<int,int>,vector<pair<int,int> > ,greater<pair<int,int> > > q;
q.push({0,1});
while(q.size()){
int u=q.top().second;
q.pop();
if(vs[u]) continue;
vs[u] = 1;
for(auto l:g[u]){
int v=l.first,w=l.second;
if(d[v]>d[u]+w){
d[v]=d[u]+w;
q.push({d[v],v});
pre[v] = u;
}
}
}
stack<int> st;
while(pre[n]){
st.push(n);
n=pre[n];
}
st.push(1);
while(st.size()){
cout<<st.top()<<' ';
st.pop();
}
return 0;
}