#include <bits/stdc++.h>
using namespace std;
class Node {
 public:
  signed long long int index, value, visited, parent;
  vector<pair<signed long long int, signed long long int> > adj;
  Node() {
    index = -1;
    visited = 0;
    parent = -1;
    value = 9223372036854775807;
  }
  bool operator<(const Node& b) const { return this->value < b.value; }
  bool operator>(const Node& b) const { return this->value > b.value; }
  bool operator==(const Node& b) const { return this->index == b.index; }
};
int main() {
  signed long long int n, m, i, j, u, v, dist;
  cin >> n >> m;
  vector<Node> grp(n);
  for (i = 0; i < n; i++) {
    grp[i].index = i;
  }
  for (i = 0; i < m; i++) {
    cin >> u >> v >> dist;
    u--;
    v--;
    grp[u].adj.push_back({v, dist});
    grp[v].adj.push_back({u, dist});
  }
  signed long long int source, dest;
  source = 0;
  set<pair<signed long long int, signed long long int> > curr;
  grp[source].value = 0;
  curr.insert({0, 0});
  while (curr.size() > 0) {
    signed long long int present = (*curr.begin()).second;
    curr.erase(curr.begin());
    grp[present].visited = 1;
    for (i = 0; i < grp[present].adj.size(); i++) {
      signed long long int to = grp[present].adj[i].first;
      if (grp[to].value > (grp[present].value + grp[present].adj[i].second)) {
        if (curr.find({grp[to].value, to}) != curr.end()) {
          curr.erase(curr.find({grp[to].value, to}));
        }
        grp[to].value = grp[present].value + grp[present].adj[i].second;
        grp[to].parent = present;
        curr.insert({grp[to].value, to});
      }
    }
  }
  dest = n - 1;
  vector<signed long long int> result;
  while (dest != -1) {
    result.push_back(dest + 1);
    dest = grp[dest].parent;
  }
  if (grp[n - 1].value < 9223372036854775807) {
    for (i = result.size() - 1; i >= 0; i--) {
      cout << result[i] << " ";
    }
    cout << endl;
  } else
    cout << -1 << endl;
  return 0;
}
