#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
using pii = std::pair<long long, long long>;
using namespace std;
long long n, m, a, b, w;
vector<vector<pii>> adj;
vector<long long> ans;
long long dist[100005], parent[100005];
void dijkstra(long long s, long long e) {
  for (long long i = (0); i < (n); i++) {
    dist[i] = (long long)1e12;
    parent[i] = -1;
  }
  dist[s] = 0;
  priority_queue<pii, vector<pii>, greater<pii>> pq;
  pq.push({0, s});
  long long v, d, to, length;
  while (!pq.empty()) {
    d = pq.top().first;
    v = pq.top().second;
    pq.pop();
    if (d != dist[v])
      continue;
    else if (v == e)
      return;
    for (pii edge : adj[v]) {
      length = edge.first;
      to = edge.second;
      if (dist[v] + length < dist[to]) {
        dist[to] = dist[v] + length;
        parent[to] = v;
        pq.push({dist[to], to});
      }
    }
  }
}
void getParents(long long x) {
  if (parent[x] != -1) getParents(parent[x]);
  ans.push_back(x + 1);
}
class CDijkstra {
 public:
  void solve(std::istream& in, std::ostream& out) {
    in >> n >> m;
    adj.resize(n);
    for (long long i = (0); i < (m); i++) {
      in >> a >> b >> w;
      adj[a - 1].push_back({w, b - 1});
      adj[b - 1].push_back({w, a - 1});
    }
    dijkstra(0, n - 1);
    getParents(n - 1);
    if (ans[0] != 1)
      out << -1 << "\n";
    else
      for (long long i = (0); i < (ans.size()); i++) out << ans[i] << " ";
    out << "\n";
  }
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  CDijkstra solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
