#include <bits/stdc++.h>
using namespace std;
long int mod = 1000000007;
const long long N = 1e5 + 3;
const long long inf = 1000000000000000000;
unordered_map<long long, list<pair<long long, long long>>> m;
vector<long long> path(N, -1);
vector<long long> dist(N, inf);
void dijstra(long long src, long long dest) {
  set<pair<long long, long long>> s;
  s.insert(make_pair(0, src));
  path[src] = 0;
  long long node, nodedis;
  while (s.empty() == false) {
    auto it = *(s.begin());
    node = it.second;
    nodedis = it.first;
    s.erase(it);
    for (auto neigh : m[node]) {
      if (nodedis + neigh.second < dist[neigh.first]) {
        auto f = s.find(make_pair(dist[neigh.first], neigh.first));
        if (f != s.end()) s.erase(make_pair(dist[neigh.first], neigh.first));
        dist[neigh.first] = nodedis + neigh.second;
        s.insert(make_pair(dist[neigh.first], neigh.first));
        path[neigh.first] = node;
      }
    }
  }
  if (path[dest] == -1)
    cout << -1;
  else {
    vector<long long> pp;
    for (long long i = dest; i != src;) {
      pp.push_back(i);
      i = path[i];
    }
    reverse(pp.begin(), pp.end());
    cout << src << " ";
    for (auto it : pp) cout << it << " ";
  }
}
int main() {
  long long n, e;
  cin >> n >> e;
  while (e--) {
    long long u, v, dis;
    cin >> u >> v >> dis;
    m[u].push_back(make_pair(v, dis));
    m[v].push_back(make_pair(u, dis));
  }
  dijstra(1, n);
  return 0;
}
