#include <bits/stdc++.h>
using namespace std;
int main(void) {
  std::ios::sync_with_stdio(false);
  long long n, m, aux, a, b;
  cin >> n >> m;
  pair<long long, long long> for_h;
  vector<vector<pair<long long, long long> > > v(n);
  set<pair<long long, long long> > dtra;
  vector<char> used(n, 0);
  vector<long long> right_weight(n, 1e15);
  vector<long long> ancestor(n, -1);
  for (long long i = 0; i < m; i++) {
    cin >> a >> b >> aux;
    a--, b--;
    v[a].push_back(make_pair(b, aux));
    v[b].push_back(make_pair(a, aux));
  }
  ancestor[0] = 0;
  right_weight[0] = 0;
  for (int i = 0; i < n; i++) dtra.insert(make_pair(right_weight[i], i));
  long long from;
  while (!dtra.empty()) {
    from = dtra.begin()->second;
    dtra.erase(dtra.begin());
    if (used[from] != 1) {
      used[from] = 1;
      for (long long j = 0; j < v[from].size(); j++) {
        for_h.second = v[from][j].first;
        for_h.first = right_weight[for_h.second];
        dtra.erase(for_h);
        if (right_weight[for_h.second] >
            right_weight[from] + v[from][j].second) {
          right_weight[for_h.second] = right_weight[from] + v[from][j].second;
          ancestor[for_h.second] = from;
        }
        for_h.first = right_weight[for_h.second];
        dtra.insert(for_h);
      }
    }
  }
  if (ancestor[n - 1] == -1) {
    cout << -1;
    return 0;
  }
  stack<int> path;
  int iter = n - 1;
  while (iter != 0) {
    path.push(iter + 1);
    iter = ancestor[iter];
  }
  path.push(1);
  while (!path.empty()) {
    cout << path.top() << ' ';
    path.pop();
  }
  cout << '\n';
  return 0;
}
