#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
vector<pair<int, int> > adj[100001];
int re[100001];
long long dist[100001];
long long dijsktra(int from, int to, int n) {
  long long sz, x, w, cost, at;
  for (int i = 0; i < n + 1; i++) dist[i] = 1000000000000;
  dist[from] = 0;
  priority_queue<pair<long long, long long> > q;
  q.push(make_pair(0, from));
  memset(re, 0, sizeof(re));
  re[from] = -1;
  while (!q.empty()) {
    pair<long long, long long> pp = q.top();
    q.pop();
    at = pp.second, cost = -pp.first, sz = adj[at].size();
    if (dist[at] < cost) continue;
    if (at == to) break;
    for (int i = 0; i < sz; ++i) {
      x = adj[at][i].first, w = adj[at][i].second;
      if (dist[x] > cost + w) {
        dist[x] = cost + w;
        q.push(make_pair(-dist[x], x));
        re[x] = at;
      }
    }
  }
  return dist[to];
}
void prn(int x) {
  vector<int> v;
  while (x != 1) {
    v.push_back(x);
    x = re[x];
  }
  v.push_back(1);
  for (int i = ((int)v.size()) - 1; i >= 0; i--) {
    cout << v[i] << " ";
  }
}
int main(void) {
  int n, m, a, b, c;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c;
    adj[a].push_back(make_pair(b, c));
    adj[b].push_back(make_pair(a, c));
  }
  if (dijsktra(1, n, n) >= 1000000000000)
    cout << -1;
  else {
    prn(n);
  }
  return 0;
}
