#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
int pre[100001];
int n, m, a, b, w;
vector<pair<int, int>> G[100001];
long long dist[100001];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
    min_dist;
void Dij(int src) {
  for (int i = 1; i <= n; i++) {
    if (i != src) dist[i] = INF;
    min_dist.push({dist[i], i});
  }
  while (!min_dist.empty()) {
    int V = min_dist.top().second;
    min_dist.pop();
    for (auto to : G[V]) {
      if (to.second + dist[V] < dist[to.first]) {
        pre[to.first] = V;
        dist[to.first] = to.second + dist[V];
        min_dist.push({dist[to.first], to.first});
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  cin >> n >> m;
  fill(pre, pre + 100001, -1);
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> w;
    G[a].push_back({b, w});
    G[b].push_back({a, w});
  }
  Dij(1);
  stack<int> route;
  route.push(n);
  while (route.top() != 1) {
    route.push(pre[n]);
    n = pre[n];
    if (route.top() == -1) {
      cout << -1 << endl;
      return 0;
    }
  }
  while (!route.empty()) {
    cout << route.top() << ' ';
    route.pop();
  }
}
