#include <bits/stdc++.h>
using namespace std;
long long dp[200010];
int first[200010], visit[200010], k, n, f[200010], r[200010];
struct Path {
  int y, d, next;
} path[200010];
void add(int a, int b, int c) {
  path[k].y = b, path[k].d = c, path[k].next = first[a];
  first[a] = k;
  k++;
}
void spfa(int src) {
  for (int i = 1; i <= n; i++) dp[i] = -1;
  memset(f, 0, sizeof(f));
  memset(visit, 0, sizeof(visit));
  queue<int> q;
  dp[1] = 0, visit[1] = 1;
  q.push(1);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    visit[u] = 0;
    for (int i = first[u]; i != -1; i = path[i].next) {
      if (dp[path[i].y] == -1 || dp[path[i].y] > dp[u] + path[i].d) {
        dp[path[i].y] = dp[u] + path[i].d;
        f[path[i].y] = u;
        if (!visit[path[i].y]) visit[path[i].y] = 1, q.push(path[i].y);
      }
    }
  }
}
int main() {
  int m, a, b, c;
  while (scanf("%d%d", &n, &m) != EOF) {
    k = 0;
    memset(first, -1, sizeof(first));
    for (int i = 0; i < m; i++) {
      scanf("%d%d%d", &a, &b, &c);
      add(a, b, c);
      add(b, a, c);
    }
    spfa(1);
    int cnt = 0;
    for (int i = n; i != 0; i = f[i]) r[cnt++] = i;
    if (r[cnt - 1] == 1) {
      for (int i = cnt - 1; i >= 1; i--) printf("%d ", r[i]);
      printf("%d\n", r[0]);
    } else {
      printf("-1\n");
    }
  }
  return 0;
}
