#include <bits/stdc++.h>
using namespace std;
long int mod = 1000000007;
const long long N = 1e5 + 3;
const long long inf = 1000000000000000000;
vector<pair<long long, long long>> m[N];
unordered_map<long long, long long> path;
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));
  dist[src] = 0;
  path[src] = 0;
  while (s.empty() == false) {
    auto zz = *(s.begin());
    long long u = zz.second;
    s.erase(s.begin());
    for (auto neigh : m[u]) {
      long long d = neigh.second;
      long long v = neigh.first;
      if (dist[u] + d < dist[v]) {
        auto f = s.find(make_pair(dist[v], v));
        if (f != s.end()) s.erase(make_pair(dist[v], v));
        dist[v] = dist[u] + d;
        path[v] = u;
        s.insert(make_pair(dist[v], v));
      }
    }
  }
  if (dist[dest] == inf) {
    cout << -1;
  } else {
    vector<long long> route;
    route.push_back(dest);
    long long ffao = path[dest];
    while (ffao != 0) {
      route.push_back(ffao);
      ffao = path[ffao];
    }
    for (int i = route.size() - 1; i >= 0; i--) cout << route[i] << " ";
  }
}
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;
}
