#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e15;
long long d[100001], trace[100001];
vector<pair<int, long long> > a[100001];
vector<int> path;
int n, m, u, v, w;
struct cmp {
  bool operator()(pair<int, long long> a, pair<int, long long> b) {
    return a.second > b.second;
  }
};
void dijkstra() {
  priority_queue<pair<int, long long>, vector<pair<int, long long> >, cmp> q;
  long long u, v, uu, vv;
  for (int i = 1; i <= n; i++) d[i] = oo;
  for (int i = 1; i <= n; i++) a[i].push_back(pair<int, long long>(0, 0));
  d[1] = 0;
  q.push(pair<int, long long>(1, 0));
  while (q.size() != 0) {
    u = q.top().first;
    v = q.top().second;
    q.pop();
    for (int i = 0; i <= (int)a[u].size() - 1; i++) {
      uu = a[u][i].first;
      vv = a[u][i].second;
      if (d[uu] > v + vv) {
        trace[uu] = u;
        d[uu] = v + vv;
        q.push(pair<int, long long>(uu, d[uu]));
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> u >> v >> w;
    a[u].push_back(pair<int, long long>(v, w));
    a[v].push_back(pair<int, long long>(u, w));
  }
  for (int i = 1; i <= n; i++) trace[i] = -1;
  dijkstra();
  int s = n;
  while (trace[s] != -1) {
    path.push_back(s);
    s = trace[s];
  }
  path.push_back(1);
  if (path.size() > 1)
    for (int i = path.size() - 1; i >= 0; i--) cout << path[i] << " ";
  else
    cout << -1;
  return 0;
  return 0;
}
