#include <bits/stdc++.h>
using namespace std;
array<vector<pair<long long, int> >, 100001> adj;
array<long long, 100001> dis;
array<int, 100001> parent;
void dij(int n) {
  dis.fill(2e17);
  dis[n] = 0;
  priority_queue<pair<long long, int> > q;
  q.push({0, n});
  pair<long long, int> cp, to;
  while (!q.empty()) {
    cp = q.top();
    cp.first *= -1;
    q.pop();
    if (dis[cp.second] < cp.first) continue;
    if (cp.second == 1) break;
    for (auto to : adj[cp.second]) {
      if (dis[to.second] > cp.first + to.first) {
        dis[to.second] = cp.first + to.first;
        q.push({-dis[to.second], to.second});
        parent[to.second] = cp.second;
      }
    }
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int f, t, c;
  while (m--) {
    scanf("%d %d %d", &f, &t, &c);
    adj[f].push_back({c, t});
    adj[t].push_back({c, f});
  }
  dij(n);
  if (!parent[1]) {
    printf("%d", -1);
    return 0;
  }
  int x = 1;
  while (x) {
    printf("%d ", x);
    x = parent[x];
  }
  return 0;
}
