#include <bits/stdc++.h>
using namespace std;
int ini() {
  int t;
  scanf("%d", &t);
  return t;
}
vector<vector<pair<long long, long long> > > asd;
int pr[100000 + 5];
vector<int> p;
void path(int u) {
  if (u == 0) return;
  path(pr[u]);
  p.push_back(u);
}
int main() {
  int v = ini(), e = ini();
  asd.assign(v + 1, vector<pair<long long, long long> >());
  for (int i = 0; i < e; i++) {
    int from = ini(), to = ini(), w = ini();
    from--, to--;
    asd[from].push_back(make_pair(to, w));
    asd[to].push_back(make_pair(from, w));
  }
  long long dist[100000 + 5];
  for (int i = 0; i <= 100001; i++) {
    pr[i] = i;
    dist[i] = 1LL << 62;
  }
  long long INF = dist[0];
  int s = 0;
  dist[s] = 0;
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      pq;
  pq.push(pair<long long, long long>(0, s));
  while (!pq.empty()) {
    pair<long long, long long> top = pq.top();
    pq.pop();
    int u = top.second;
    long long w = top.first;
    if (dist[u] == w) {
      for (__typeof(asd[u].begin()) it = asd[u].begin(); it != asd[u].end();
           it++) {
        long long v = it->first;
        long long uv = it->second;
        long long duv = dist[u] + uv;
        if (duv < dist[v]) {
          dist[v] = duv;
          pq.push(pair<long long, long long>(duv, v));
          pr[v] = u;
        }
      }
    }
  }
  if (dist[v - 1] == INF)
    printf("-1\n");
  else {
    path(v - 1);
    printf("%d ", 1);
    for (int i = 0; i < p.size(); i++) printf("%d ", p[i] + 1);
  }
}
