#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
long long int path[100001];
long long int dist[100001];
void shortest_path(vector<pair<long long int, long long int>> v[],
                   long long int start) {
  long long int i;
  for (long long int i = 0; i < 100001; i++) dist[i] = 1e18 + 1;
  priority_queue<pair<long long int, long long int>,
                 vector<pair<long long int, long long int>>,
                 greater<pair<long long int, long long int>>>
      q;
  q.push(make_pair(0, start));
  dist[start] = 0;
  while (!q.empty()) {
    long long int x = q.top().second;
    q.pop();
    for (i = 0; i < v[x].size(); i++) {
      if (dist[v[x][i].first] > dist[x] + v[x][i].second) {
        dist[v[x][i].first] = dist[x] + v[x][i].second;
        path[v[x][i].first] = x;
        q.push(make_pair(dist[v[x][i].first], v[x][i].first));
      }
    }
  }
}
void solve() {
  long long int ver, edge, i, x, y, w, start = 1;
  cin >> ver >> edge;
  vector<pair<long long int, long long int>> v[ver + 1];
  vector<long long int> ans;
  for (i = 0; i < edge; i++) {
    cin >> x >> y >> w;
    v[x].push_back(make_pair(y, w));
    v[y].push_back(make_pair(x, w));
  }
  shortest_path(v, start);
  if (dist[ver] == 1e18 + 1)
    cout << "-1"
         << "\n";
  else {
    cout << "1 ";
    while (ver != 1) {
      ans.push_back(ver);
      ver = path[ver];
    }
    for (i = ans.size() - 1; i >= 0; i--) {
      cout << ans[i] << " ";
    }
    cout << "\n";
  }
}
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  fast();
  int t = 1;
  while (t--) solve();
  return 0;
}
