#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> g[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  while (m--) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a].push_back(make_pair(b, c));
    g[b].push_back(make_pair(a, c));
  }
  long long dist[n + 1];
  int par[n + 1];
  for (int i = 1; i <= n; i++) dist[i] = 1e18;
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      q;
  q.push({0, 1});
  dist[1] = 0;
  while (!q.empty()) {
    int x = q.top().second;
    q.pop();
    for (auto p : g[x]) {
      if (dist[x] + p.second < dist[p.first]) {
        dist[p.first] = dist[x] + p.second;
        par[p.first] = x;
        q.push({dist[p.first], p.first});
      }
    }
  }
  if (dist[n] == 1e18) {
    cout << -1;
    return 0;
  }
  vector<int> out;
  cout << 1 << " ";
  for (int x = n; x != 1; x = par[x]) out.push_back(x);
  for (int i = out.size() - 1; i >= 0; i--) cout << out[i] << " ";
}
