You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.

The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that the graph has loops and multiple edges between pair of vertices.

Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.

'use strict';

//const PriorityQueue = require('priorityqueuejs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;
const INF = Math.pow(10, 12);

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

/**
 * Expose `PriorityQueue`.
 */
// module.exports = PriorityQueue;

/**
 * Initializes a new empty `PriorityQueue` with the given `comparator(a, b)`
 * function, uses `.DEFAULT_COMPARATOR()` when no function is provided.
 *
 * The comparator function must return a positive number when `a > b`, 0 when
 * `a == b` and a negative number when `a < b`.
 *
 * @param {Function}
 * @return {PriorityQueue}
 * @api public
 */

function PriorityQueue(comparator) {
  this._comparator = comparator || PriorityQueue.DEFAULT_COMPARATOR;
  this._elements = [];
}

PriorityQueue.DEFAULT_COMPARATOR = function(a, b) {
  if (typeof a === 'number' && typeof b === 'number') {
    return a - b;
  } else {
    a = a.toString();
    b = b.toString();

    if (a == b) return 0;

    return (a > b) ? 1 : -1;
  }
};

PriorityQueue.prototype.isEmpty = function() {
  return this.size() === 0;
};

PriorityQueue.prototype.peek = function() {
  if (this.isEmpty()) throw new Error('PriorityQueue is empty');

  return this._elements[0];
};

PriorityQueue.prototype.deq = function() {
  var first = this.peek();
  var last = this._elements.pop();
  var size = this.size();

  if (size === 0) return first;

  this._elements[0] = last;
  var current = 0;

  while (current < size) {
    var largest = current;
    var left = (2 * current) + 1;
    var right = (2 * current) + 2;

    if (left < size && this._compare(left, largest) >= 0) {
      largest = left;
    }

    if (right < size && this._compare(right, largest) >= 0) {
      largest = right;
    }

    if (largest === current) break;

    this._swap(largest, current);
    current = largest;
  }

  return first;
};

PriorityQueue.prototype.enq = function(element) {
  var size = this._elements.push(element);
  var current = size - 1;

  while (current > 0) {
    var parent = Math.floor((current - 1) / 2);

    if (this._compare(current, parent) <= 0) break;

    this._swap(parent, current);
    current = parent;
  }

  return size;
};

PriorityQueue.prototype.size = function() {
  return this._elements.length;
};

PriorityQueue.prototype.forEach = function(fn) {
  return this._elements.forEach(fn);
};

PriorityQueue.prototype._compare = function(a, b) {
  return this._comparator(this._elements[a], this._elements[b]);
};

PriorityQueue.prototype._swap = function(a, b) {
  var aux = this._elements[a];
  this._elements[a] = this._elements[b];
  this._elements[b] = aux;
};

let nodes, edges;
let edgeList = [];

const getInput = () => {
    const lineInput = readline().split(" ").map(Number);
    nodes = lineInput[0], edges = lineInput[1];

    edgeList = new Array(nodes + 1);
    for(let i  = 0; i < nodes + 1; i++){
        edgeList[i] = new Array();
        edgeList[i].push(0);
    }

    for(let i = 0; i < edges; i++){
        const lineInput = readline().split(" ").map(Number);
        let node1 = lineInput[0], node2 = lineInput[1], weight = lineInput[2];

        edgeList[node1].push({"to": node2, "weight": weight});
        edgeList[node2].push({"to": node1, "weight": weight});
    }
};

const dijkstra = (source, destination) => {
    let distance = new Array(nodes + 1).fill(INF);
    let pQueue = new PriorityQueue(function(v1, v2) {
        return v2.weight - v1.weight;
    });
    let visited = new Array(nodes + 1).fill(false);
    let parent = new Array(nodes + 1).fill(-1);

    distance[source] = 0;
    pQueue.enq({node: source, weight: 0});

    while(!pQueue.isEmpty()) {
        const { node, weight } = pQueue.peek();
        pQueue.deq();

        if(weight === INF)
            break;
        if(visited[node]) continue;
        visited[node] = true;

        for(let edge of edgeList[node]){
            const {to, weight: currentWeight } = edge;

            if(distance[to] > weight + currentWeight){
                distance[to] = weight + currentWeight;
                pQueue.enq({node: to, weight: distance[to]})
                parent[to] = node;
            }
        }

    }

    if(distance[destination] === INF)
        return "-1";

    let path = "";
    let currentNode = destination
    while(parent[currentNode] !== -1){
        path += currentNode.toString() + " ";
        currentNode = parent[currentNode];
    }
    path += currentNode.toString();
    path = path.split(" ").reverse().join(" ");

    return path;
}

function main() {
    getInput();
    const result = dijkstra(1, nodes);
    console.log(result);
}

!function(t){var n={};function r(e){if(n[e])return n[e].exports;var i=n[e]={i:e,l:!1,exports:{}};return t[e].call(i.exports,i,i.exports,r),i.l=!0,i.exports}r.m=t,r.c=n,r.d=function(t,n,e){r.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:e})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,n){if(1&n&&(t=r(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var i in t)r.d(e,i,function(n){return t[n]}.bind(null,i));return e},r.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(n,"a",n),n},r.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},r.p="",r(r.s=2)}([function(t,n,r){"use strict";n.gets=function(){try{return readline,readline}catch(t){}try{process.versions.node}catch(t){return function(){return std.in.getline()}}var t=null,n=0;return function(){if(null===t){var e=r(1).readFileSync("/dev/stdin");""===(t=String(e).split("\n"))[t.length-1]&&t.pop()}return n<t.length?t[n++]:null}}()},function(t,n){t.exports=require("fs")},function(t,n,r){"use strict";r.r(n);for(var e=r(0),i=function(t,n){if(!t)throw n=void 0===n?"":": "+n,new Error("Assertion failed"+n)},a=function(t,n){return new Array(t).fill(n)},o=function(t,n){for(var r=new Array(t),e=0;e<t;e++)r[e]=n(e);return r},u=function(){function t(t,n){if(this.cmp=t,this.data=[],void 0!==n){for(var r=n.length,e=0;e<r;e++)this.data.push([n[e],e]);for(e=r>>1;--e>=0;)this.inc(this.data[e])}}return t.prototype.size=function(){return this.data.length},t.prototype.top=function(){return i(this.data.length>0),this.data[0]},t.prototype.insert=function(t){var n=[t,this.data.length];return this.data.push(n),this.dec(n),n},t.prototype.remove=function(t){var n=t[1];i(t===this.data[n]),t=this.data.pop(),n<this.data.length&&(this.data[n]=t,t[1]=n,this.inc(t))},t.prototype.dec=function(t){var n=t[1];for(i(t===this.data[n]);n>0;){var r=n-1>>1;if(!this.cmp(t[0],this.data[r][0]))break;this.data[n]=this.data[r],this.data[n][1]=n,n=r}this.data[n]=t,t[1]=n},t.prototype.inc=function(t){var n=t[1];for(i(t===this.data[n]);;){var r=1+(n<<1);if(r>=this.data.length)break;if(r+1<this.data.length&&this.cmp(this.data[r+1][0],this.data[r][0])&&r++,!this.cmp(this.data[r][0],t[0]))break;this.data[n]=this.data[r],this.data[n][1]=n,n=r}this.data[n]=t,t[1]=n},t}(),s=e.gets().split(" ").map((function(t){return+t})),f=s[0],c=s[1],d=o(f,(function(){return[]})),l=0;l<c;l++){var h=e.gets().split(" ").map((function(t){return+t})),p=h[0],v=h[1],g=h[2];v--,d[--p].push([v,g]),d[v].push([p,g])}var y=a(f,1/0),b=new u((function(t,n){return y[t]<y[n]})),m=o(f,(function(t){return b.insert(t)})),j=a(f,-1),O=function(t,n,r){r<y[t]&&(y[t]=r,j[t]=n,b.dec(m[t]))};for(O(0,0,0);b.size()>0;){var S=b.top()[0];if(!isFinite(y[S]))break;b.remove(b.top());for(var w=0,x=d[S];w<x.length;w++){var _=x[w],P=_[0],k=_[1];O(P,S,y[S]+k)}}if(isFinite(y[f-1])){for(S=f-1,p=[];p.push(S+1),0!==S;)S=j[S];print(p.reverse().join(" "))}else print("-1")}]);

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Queue = require('../queue');
var Stack = require('../stack');

var Graph = function () {
    function Graph() {
        var _this = this;

        var nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
        var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

        _classCallCheck(this, Graph);

        this.directed = directed;
        this.nodes = nodes;
        this.edges = {};
        nodes.forEach(function (node) {
            _this.edges[node] = [];
        });
    }

    _createClass(Graph, [{
        key: 'addNode',
        value: function addNode(node) {
            // is it required ?
            if (this.edges[node]) {
                throw new Error('Graph.prototype.addNode: node is already exists');
                return;
            }

            this.nodes.push(node);
            this.edges[node] = [];
        }
    }, {
        key: 'addEdge',
        value: function addEdge(node1, node2) {
            var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;

            this.edges[node1].push({ node: node2, weight: weight });

            if (!this.directed) {
                this.edges[node2].push({ node: node1, weight: weight });
            }
        }
    }, {
        key: 'display',
        value: function display() {
            var _this2 = this;

            if (!console || !console.log) {
                return;
            }

            var graph = "";
            this.nodes.forEach(function (node) {
                graph += node + "->" + _this2.edges[node].map(function (n) {
                    return n.node;
                }).join(", ") + "\n";
            });
            console.log(graph);
        }
    }, {
        key: 'BFS',
        value: function BFS(node) {
            var q = new Queue();
            var explored = new Set();
            q.enqueue(node);
            explored.add(node);
            while (!q.isEmpty()) {
                var t = q.dequeue();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    q.enqueue(n);
                });
            }
        }
    }, {
        key: 'DFS',
        value: function DFS(node) {
            var s = new Stack();
            var explored = new Set();
            s.push(node);
            explored.add(node);

            while (!s.isEmpty()) {
                var t = s.pop();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    s.push(n);
                });
            }
        }
    }]);

    return Graph;
}();

module.exports = Graph;

},{"../queue":4,"../stack":5}],2:[function(require,module,exports){
"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = function () {
    function Node(value) {
        _classCallCheck(this, Node);

        this.value = value;
        this.nextNode = null;
        this.prevNode = null;
    }

    _createClass(Node, [{
        key: "getValue",
        value: function getValue() {
            return this.value;
        }
    }, {
        key: "setValue",
        value: function setValue(value) {
            this.value = value;
        }
    }, {
        key: "setNext",
        value: function setNext(nextNodeLink) {
            this.nextNode = nextNodeLink;
        }
    }, {
        key: "setPrev",
        value: function setPrev(prevNodeLink) {
            this.prevNode = prevNodeLink;
        }
    }, {
        key: "getNext",
        value: function getNext() {
            return this.nextNode;
        }
    }, {
        key: "getPrev",
        value: function getPrev() {
            return this.prevNode;
        }
    }]);

    return Node;
}();

module.exports = Node;

},{}],3:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item, priority) {
            var node = new Node({
                item: item,
                priority: priority
            });

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {

                if (priority >= this.firstItemLink.getValue().priority) {
                    // Вперед
                    node.setNext(this.firstItemLink);
                    this.firstItemLink = node;
                } else if (priority <= this.lastItemLink.getValue().priority) {
                    // Назад
                    this.lastItemLink.setNext(node);
                    this.lastItemLink = node;
                } else {
                    // В середину
                    var currentNode = this.firstItemLink;
                    while (currentNode) {
                        var nextNode = currentNode.getNext();
                        if (priority >= nextNode.getValue().priority) {
                            currentNode.setNext(node);
                            node.setNext(nextNode);
                            currentNode = null;
                        } else {
                            currentNode = nextNode;
                        }
                    }
                }
            }
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue().item;
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],4:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {
                this.lastItemLink.setNext(node);
                this.lastItemLink = node;
            }

            return node;
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],5:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Stack = function () {
    function Stack() {
        _classCallCheck(this, Stack);

        this.topItemLink = null;
    }

    _createClass(Stack, [{
        key: 'push',
        value: function push(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.topItemLink = node;
            } else {
                node.setPrev(this.topItemLink);
                this.topItemLink = node;
            }

            return node;
        }
    }, {
        key: 'pop',
        value: function pop() {
            if (this.isEmpty()) {
                return undefined;
            }

            var topItemLink = this.topItemLink;

            this.topItemLink = this.topItemLink.getPrev();

            return topItemLink.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.topItemLink;
        }
    }]);

    return Stack;
}();

module.exports = Stack;

},{"../node":2}],6:[function(require,module,exports){
'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var Graph = require('../libs/graph');
var PriorityQueue = require('../libs/priority-queue');

var _readline$split$map = readline().split(' ').map(function (n) {
    return parseInt(n);
}),
    _readline$split$map2 = _slicedToArray(_readline$split$map, 2),
    n = _readline$split$map2[0],
    m = _readline$split$map2[1];

var G = new Graph();
for (var i = 1; i <= n; i++) {
    G.addNode(i);
}

for (var _i = 0; _i < m; _i++) {
    var _readline$split$map3 = readline().split(' ').map(function (n) {
        return parseInt(n);
    }),
        _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),
        a = _readline$split$map4[0],
        b = _readline$split$map4[1],
        w = _readline$split$map4[2];

    if (a !== b) G.addEdge(a, b, w);
}

var pq = new PriorityQueue(n * n);
var distances = {};
var prev = {};

// for(let i = 1; i<=n; i++) {
//     prev[i] = null;
//     distances[i] = Infinity;
// }

distances[1] = 0;
pq.enqueue(1, 0);

var explored = new Set();

var _loop = function _loop() {
    var node = pq.dequeue();

    explored.add(node);
    // console.log('Открыл ноду и отметил как прочитанную', node, ' Соседи', G.edges[node].map(({node}) => node).join(','));/**/
    G.edges[node].forEach(function (neighbor) {

        // if (!explored.has(neighbor.node)) {
        //     console.log('Открыл ноду', neighbor);
        var alt = distances[node] + neighbor.weight;

        if (distances[neighbor.node] === undefined || distances[neighbor.node] > alt) {
            // console.log('Добавил ноду', neighbor, 'В очередь');
            distances[neighbor.node] = alt;
            prev[neighbor.node] = node;
            pq.enqueue(neighbor.node, -1 * distances[neighbor.node]);
            // console.log('priority of node', distances[neighbor.node], JSON.stringify(pq.container));
        }
        // } else {
        //     // console.log('Собрался идти на ноду', neighbor.node, 'но она уже помечена');
        // }
    });
};

while (!pq.isEmpty()) {
    _loop();
}

if (prev[n]) {
    var path = n;
    var currNode = n;
    while (prev[currNode]) {
        path = prev[currNode] + ' ' + path;
        currNode = prev[currNode];
    }

    write(path);
} else {
    write('-1');
}

},{"../libs/graph":1,"../libs/priority-queue":3}]},{},[6]);

/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ 		}
/******/ 	};
/******/
/******/ 	// define __esModule on exports
/******/ 	__webpack_require__.r = function(exports) {
/******/ 		if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ 			Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ 		}
/******/ 		Object.defineProperty(exports, '__esModule', { value: true });
/******/ 	};
/******/
/******/ 	// create a fake namespace object
/******/ 	// mode & 1: value is a module id, require it
/******/ 	// mode & 2: merge all properties of value into the ns
/******/ 	// mode & 4: return value when already ns object
/******/ 	// mode & 8|1: behave like require
/******/ 	__webpack_require__.t = function(value, mode) {
/******/ 		if(mode & 1) value = __webpack_require__(value);
/******/ 		if(mode & 8) return value;
/******/ 		if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ 		var ns = Object.create(null);
/******/ 		__webpack_require__.r(ns);
/******/ 		Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ 		if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ 		return ns;
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = "./build/a.js");
/******/ })
/************************************************************************/
/******/ ({

/***/ "./build/_/ds/heap.js":
/*!****************************!*\
  !*** ./build/_/ds/heap.js ***!
  \****************************/
/*! exports provided: BinaryHeap */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"BinaryHeap\", function() { return BinaryHeap; });\n/* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../util */ \"./build/_/util.js\");\n\nclass BinaryHeap {\n    constructor(cmp, a) {\n        this.cmp = cmp;\n        this.data = [];\n        if (a !== undefined) {\n            const n = a.length;\n            for (let i = 0; i < n; i++)\n                this.data.push([a[i], i]);\n            for (let i = n >> 1; --i >= 0;)\n                this.inc(this.data[i]);\n        }\n    }\n    size() {\n        return this.data.length;\n    }\n    top() {\n        _util__WEBPACK_IMPORTED_MODULE_0__[\"assert\"](this.data.length > 0);\n        return this.data[0];\n    }\n    insert(x) {\n        const it = [x, this.data.length];\n        this.data.push(it);\n        this.dec(it);\n        return it;\n    }\n    remove(it) {\n        const i = it[1];\n        _util__WEBPACK_IMPORTED_MODULE_0__[\"assert\"](it === this.data[i]);\n        it = this.data.pop();\n        if (i < this.data.length) {\n            this.data[i] = it;\n            it[1] = i;\n            this.inc(it);\n        }\n    }\n    dec(it) {\n        let i = it[1];\n        _util__WEBPACK_IMPORTED_MODULE_0__[\"assert\"](it === this.data[i]);\n        while (i > 0) {\n            const p = (i - 1) >> 1;\n            if (!this.cmp(it[0], this.data[p][0]))\n                break;\n            this.data[i] = this.data[p];\n            this.data[i][1] = i;\n            i = p;\n        }\n        this.data[i] = it;\n        it[1] = i;\n    }\n    inc(it) {\n        let i = it[1];\n        _util__WEBPACK_IMPORTED_MODULE_0__[\"assert\"](it === this.data[i]);\n        for (;;) {\n            let j = (i << 1) + 1;\n            if (j >= this.data.length)\n                break;\n            if (j + 1 < this.data.length && this.cmp(this.data[j + 1][0], this.data[j][0]))\n                j++;\n            if (!this.cmp(this.data[j][0], it[0]))\n                break;\n            this.data[i] = this.data[j];\n            this.data[i][1] = i;\n            i = j;\n        }\n        this.data[i] = it;\n        it[1] = i;\n    }\n}\n\n\n//# sourceURL=webpack:///./build/_/ds/heap.js?");

/***/ }),

/***/ "./build/_/io.js":
/*!***********************!*\
  !*** ./build/_/io.js ***!
  \***********************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
eval("\nexports.gets = (() => {\n    try {\n        readline;\n        return readline;\n    }\n    catch (err) { }\n    try {\n        process.versions.node;\n    }\n    catch (err) {\n        return () => std.in.getline();\n    }\n    let lines = null;\n    let i = 0;\n    return () => {\n        if (lines === null) {\n            const b = __webpack_require__(/*! fs */ \"fs\").readFileSync('/dev/stdin');\n            lines = String(b).split('\\n');\n            if (lines[lines.length - 1] === '')\n                lines.pop();\n        }\n        return i < lines.length ? lines[i++] : null;\n    };\n})();\n\n\n//# sourceURL=webpack:///./build/_/io.js?");

/***/ }),

/***/ "./build/_/util.js":
/*!*************************!*\
  !*** ./build/_/util.js ***!
  \*************************/
/*! exports provided: assert, make_array, build_array */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"assert\", function() { return assert; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"make_array\", function() { return make_array; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"build_array\", function() { return build_array; });\nconst assert = (c, s) => {\n    if (!c) {\n        s = (s === undefined ? '' : ': ' + s);\n        throw new Error('Assertion failed' + s);\n    }\n};\nconst make_array = (n, x) => new Array(n).fill(x);\nconst build_array = (n, f) => {\n    const a = new Array(n);\n    for (let i = 0; i < n; i++)\n        a[i] = f(i);\n    return a;\n};\n\n\n//# sourceURL=webpack:///./build/_/util.js?");

/***/ }),

/***/ "./build/a.js":
/*!********************!*\
  !*** ./build/a.js ***!
  \********************/
/*! no exports provided */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _io__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./_/io */ \"./build/_/io.js\");\n/* harmony import */ var _io__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_io__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./_/util */ \"./build/_/util.js\");\n/* harmony import */ var _ds_heap__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./_/ds/heap */ \"./build/_/ds/heap.js\");\n\n\n\nlet S;\nS = _io__WEBPACK_IMPORTED_MODULE_0__[\"gets\"]().split(' ').map((s) => +s);\nconst N = S[0];\nconst M = S[1];\nconst E = _util__WEBPACK_IMPORTED_MODULE_1__[\"build_array\"](N, () => []);\nfor (let i = 0; i < M; i++) {\n    S = _io__WEBPACK_IMPORTED_MODULE_0__[\"gets\"]().split(' ').map((s) => +s);\n    const a = S[0] - 1;\n    const b = S[1] - 1;\n    const c = S[2];\n    E[a].push([b, c]);\n    E[b].push([a, c]);\n}\nconst D = _util__WEBPACK_IMPORTED_MODULE_1__[\"make_array\"](N, Infinity);\nconst P = _util__WEBPACK_IMPORTED_MODULE_1__[\"make_array\"](N, -1);\nconst cmp = (a, b) => D[a] < D[b];\nconst H = new _ds_heap__WEBPACK_IMPORTED_MODULE_2__[\"BinaryHeap\"](cmp);\nconst I = _util__WEBPACK_IMPORTED_MODULE_1__[\"build_array\"](N, (u) => H.insert(u));\nconst update = (u, p, d) => {\n    if (d < D[u]) {\n        D[u] = d;\n        P[u] = p;\n        H.dec(I[u]);\n    }\n};\nupdate(0, 0, 0);\nwhile (H.size() > 0) {\n    const it = H.top();\n    H.remove(it);\n    const u = it[0];\n    for (const e of E[u]) {\n        const v = e[0];\n        const w = e[1];\n        update(v, u, D[u] + w);\n    }\n}\nif (!Number.isFinite(D[N - 1])) {\n    print('-1');\n}\nelse {\n    const p = [];\n    for (let u = N - 1;;) {\n        p.push(u + 1);\n        if (u === 0)\n            break;\n        u = P[u];\n    }\n    p.reverse();\n    print(p.join(' '));\n}\n\n\n//# sourceURL=webpack:///./build/a.js?");

/***/ }),

/***/ "fs":
/*!*********************!*\
  !*** external "fs" ***!
  \*********************/
/*! no static exports found */
/***/ (function(module, exports) {

eval("module.exports = require(\"fs\");\n\n//# sourceURL=webpack:///external_%22fs%22?");

/***/ })

/******/ });

'use strict';

//const PriorityQueue = require('priorityqueuejs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;
const INF = Math.pow(10, 12);

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

/**
 * Expose `PriorityQueue`.
 */
// module.exports = PriorityQueue;

/**
 * Initializes a new empty `PriorityQueue` with the given `comparator(a, b)`
 * function, uses `.DEFAULT_COMPARATOR()` when no function is provided.
 *
 * The comparator function must return a positive number when `a > b`, 0 when
 * `a == b` and a negative number when `a < b`.
 *
 * @param {Function}
 * @return {PriorityQueue}
 * @api public
 */

function PriorityQueue(comparator) {
  this._comparator = comparator || PriorityQueue.DEFAULT_COMPARATOR;
  this._elements = [];
}

PriorityQueue.DEFAULT_COMPARATOR = function(a, b) {
  if (typeof a === 'number' && typeof b === 'number') {
    return a - b;
  } else {
    a = a.toString();
    b = b.toString();

    if (a == b) return 0;

    return (a > b) ? 1 : -1;
  }
};

PriorityQueue.prototype.isEmpty = function() {
  return this.size() === 0;
};

PriorityQueue.prototype.peek = function() {
  if (this.isEmpty()) throw new Error('PriorityQueue is empty');

  return this._elements[0];
};

PriorityQueue.prototype.deq = function() {
  var first = this.peek();
  var last = this._elements.pop();
  var size = this.size();

  if (size === 0) return first;

  this._elements[0] = last;
  var current = 0;

  while (current < size) {
    var largest = current;
    var left = (2 * current) + 1;
    var right = (2 * current) + 2;

    if (left < size && this._compare(left, largest) >= 0) {
      largest = left;
    }

    if (right < size && this._compare(right, largest) >= 0) {
      largest = right;
    }

    if (largest === current) break;

    this._swap(largest, current);
    current = largest;
  }

  return first;
};

PriorityQueue.prototype.enq = function(element) {
  var size = this._elements.push(element);
  var current = size - 1;

  while (current > 0) {
    var parent = Math.floor((current - 1) / 2);

    if (this._compare(current, parent) <= 0) break;

    this._swap(parent, current);
    current = parent;
  }

  return size;
};

PriorityQueue.prototype.size = function() {
  return this._elements.length;
};

PriorityQueue.prototype.forEach = function(fn) {
  return this._elements.forEach(fn);
};

PriorityQueue.prototype._compare = function(a, b) {
  return this._comparator(this._elements[a], this._elements[b]);
};

PriorityQueue.prototype._swap = function(a, b) {
  var aux = this._elements[a];
  this._elements[a] = this._elements[b];
  this._elements[b] = aux;
};

let nodes, edges;
let edgeList = [];

const getInput = () => {
    const lineInput = readline().split(" ").map(Number);
    nodes = lineInput[0], edges = lineInput[1];

    edgeList = new Array(nodes + 1);
    for(let i  = 0; i < nodes + 1; i++){
        edgeList[i] = new Array();
        edgeList[i].push(0);
    }

    for(let i = 0; i < edges; i++){
        const lineInput = readline().split(" ").map(Number);
        let node1 = lineInput[0], node2 = lineInput[1], weight = lineInput[2];

        edgeList[node1].push({"to": node2, "weight": weight});
        edgeList[node2].push({"to": node1, "weight": weight});
    }
};

const dijkstra = (source, destination) => {
    let distance = new Array(nodes + 1).fill(INF);
    let pQueue = new PriorityQueue(function(v1, v2) {
        return v2.weight - v1.weight;
    });
    let visited = new Array(nodes + 1).fill(false);
    let parent = new Array(nodes + 1).fill(-1);

    distance[source] = 0;
    pQueue.enq({node: source, weight: 0});

    while(!pQueue.isEmpty()) {
        const { node, weight } = pQueue.peek();
        pQueue.deq();

        if(weight === INF)
            break;
        if(visited[node]) continue;
        visited[node] = true;

        for(let edge of edgeList[node]){
            const {to, weight: currentWeight } = edge;

            if(distance[to] > weight + currentWeight){
                distance[to] = weight + currentWeight;
                pQueue.enq({node: to, weight: distance[to]})
                parent[to] = node;
            }
        }

    }

    if(distance[destination] === INF)
        return "-1";

    let path = "";
    let currentNode = destination
    while(parent[currentNode] !== -1){
        path += currentNode.toString() + " ";
        currentNode = parent[currentNode];
    }
    path += currentNode.toString();
    path = path.split("").reverse().join("");

    return path;
}

function main() {
    getInput();
    const result = dijkstra(1, nodes);
    console.log(result);
}

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Queue = require('../queue');
var Stack = require('../stack');

var Graph = function () {
    function Graph() {
        var _this = this;

        var nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
        var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

        _classCallCheck(this, Graph);

        this.directed = directed;
        this.nodes = nodes;
        this.edges = {};
        nodes.forEach(function (node) {
            _this.edges[node] = [];
        });
    }

    _createClass(Graph, [{
        key: 'addNode',
        value: function addNode(node) {
            // is it required ?
            if (this.edges[node]) {
                throw new Error('Graph.prototype.addNode: node is already exists');
                return;
            }

            this.nodes.push(node);
            this.edges[node] = [];
        }
    }, {
        key: 'addEdge',
        value: function addEdge(node1, node2) {
            var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;

            this.edges[node1].push({ node: node2, weight: weight });

            if (!this.directed) {
                this.edges[node2].push({ node: node1, weight: weight });
            }
        }
    }, {
        key: 'display',
        value: function display() {
            var _this2 = this;

            if (!console || !console.log) {
                return;
            }

            var graph = "";
            this.nodes.forEach(function (node) {
                graph += node + "->" + _this2.edges[node].map(function (n) {
                    return n.node;
                }).join(", ") + "\n";
            });
            console.log(graph);
        }
    }, {
        key: 'BFS',
        value: function BFS(node) {
            var q = new Queue();
            var explored = new Set();
            q.enqueue(node);
            explored.add(node);
            while (!q.isEmpty()) {
                var t = q.dequeue();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    q.enqueue(n);
                });
            }
        }
    }, {
        key: 'DFS',
        value: function DFS(node) {
            var s = new Stack();
            var explored = new Set();
            s.push(node);
            explored.add(node);

            while (!s.isEmpty()) {
                var t = s.pop();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    s.push(n);
                });
            }
        }
    }]);

    return Graph;
}();

module.exports = Graph;

},{"../queue":3,"../stack":4}],2:[function(require,module,exports){
"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = function () {
    function Node(value) {
        _classCallCheck(this, Node);

        this.value = value;
        this.nextNode = null;
        this.prevNode = null;
    }

    _createClass(Node, [{
        key: "getValue",
        value: function getValue() {
            return this.value;
        }
    }, {
        key: "setValue",
        value: function setValue(value) {
            this.value = value;
        }
    }, {
        key: "setNext",
        value: function setNext(nextNodeLink) {
            this.nextNode = nextNodeLink;
        }
    }, {
        key: "setPrev",
        value: function setPrev(prevNodeLink) {
            this.prevNode = prevNodeLink;
        }
    }, {
        key: "getNext",
        value: function getNext() {
            return this.nextNode;
        }
    }, {
        key: "getPrev",
        value: function getPrev() {
            return this.prevNode;
        }
    }]);

    return Node;
}();

module.exports = Node;

},{}],3:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {
                this.lastItemLink.setNext(node);
                this.lastItemLink = node;
            }

            return node;
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],4:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Stack = function () {
    function Stack() {
        _classCallCheck(this, Stack);

        this.topItemLink = null;
    }

    _createClass(Stack, [{
        key: 'push',
        value: function push(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.topItemLink = node;
            } else {
                node.setPrev(this.topItemLink);
                this.topItemLink = node;
            }

            return node;
        }
    }, {
        key: 'pop',
        value: function pop() {
            if (this.isEmpty()) {
                return undefined;
            }

            var topItemLink = this.topItemLink;

            this.topItemLink = this.topItemLink.getPrev();

            return topItemLink.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.topItemLink;
        }
    }]);

    return Stack;
}();

module.exports = Stack;

},{"../node":2}],5:[function(require,module,exports){
'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var Graph = require('../libs/graph');
var Queue = require('../libs/queue');

var _readline$split$map = readline().split(' ').map(function (n) {
    return Number(n);
}),
    _readline$split$map2 = _slicedToArray(_readline$split$map, 2),
    n = _readline$split$map2[0],
    m = _readline$split$map2[1];

var G = new Graph();
for (var i = 1; i <= n; i++) {
    G.addNode(i);
}

for (var _i = 0; _i < m; _i++) {
    var _readline$split$map3 = readline().split(' ').map(function (n) {
        return Number(n);
    }),
        _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),
        a = _readline$split$map4[0],
        b = _readline$split$map4[1],
        _w = _readline$split$map4[2];

    G.addEdge(a, b, _w);
}

var q = new Queue();
var explored = new Set();
var p = {};
var w = {};

w[1] = 0;
p[1] = undefined;
q.enqueue(1);
explored.add(1);

var _loop = function _loop() {
    var node = q.dequeue();

    G.edges[node].forEach(function (_ref) {
        var n = _ref.node,
            weight = _ref.weight;

        if (!explored.has(n)) {
            explored.add(n);
            q.enqueue(n);
        }

        if (w[n] === undefined || w[n] > w[node] + weight) {
            w[n] = w[node] + weight;
            p[n] = node;
        }
    });
};

while (!q.isEmpty()) {
    _loop();
}

if (explored.has(n)) {
    var _node = p[n];
    var path = [n];

    while (_node) {
        path.push(_node);
        _node = p[_node];
    }

    write(path.reverse().join(' '));
} else {
    write(-1);
}

},{"../libs/graph":1,"../libs/queue":3}]},{},[5]);

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Queue = require('../queue');
var Stack = require('../stack');

var Graph = function () {
    function Graph() {
        var _this = this;

        var nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
        var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

        _classCallCheck(this, Graph);

        this.directed = directed;
        this.nodes = nodes;
        this.edges = {};
        nodes.forEach(function (node) {
            _this.edges[node] = [];
        });
    }

    _createClass(Graph, [{
        key: 'addNode',
        value: function addNode(node) {
            // is it required ?
            if (this.edges[node]) {
                throw new Error('Graph.prototype.addNode: node is already exists');
                return;
            }

            this.nodes.push(node);
            this.edges[node] = [];
        }
    }, {
        key: 'addEdge',
        value: function addEdge(node1, node2) {
            var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;

            this.edges[node1].push({ node: node2, weight: weight });

            if (!this.directed) {
                this.edges[node2].push({ node: node1, weight: weight });
            }
        }
    }, {
        key: 'display',
        value: function display() {
            var _this2 = this;

            if (!console || !console.log) {
                return;
            }

            var graph = "";
            this.nodes.forEach(function (node) {
                graph += node + "->" + _this2.edges[node].map(function (n) {
                    return n.node;
                }).join(", ") + "\n";
            });
            console.log(graph);
        }
    }, {
        key: 'BFS',
        value: function BFS(node) {
            var q = new Queue();
            var explored = new Set();
            q.enqueue(node);
            explored.add(node);
            while (!q.isEmpty()) {
                var t = q.dequeue();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    q.enqueue(n);
                });
            }
        }
    }, {
        key: 'DFS',
        value: function DFS(node) {
            var s = new Stack();
            var explored = new Set();
            s.push(node);
            explored.add(node);

            while (!s.isEmpty()) {
                var t = s.pop();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    s.push(n);
                });
            }
        }
    }]);

    return Graph;
}();

module.exports = Graph;

},{"../queue":3,"../stack":4}],2:[function(require,module,exports){
"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = function () {
    function Node(value) {
        _classCallCheck(this, Node);

        this.value = value;
        this.nextNode = null;
        this.prevNode = null;
    }

    _createClass(Node, [{
        key: "getValue",
        value: function getValue() {
            return this.value;
        }
    }, {
        key: "setValue",
        value: function setValue(value) {
            this.value = value;
        }
    }, {
        key: "setNext",
        value: function setNext(nextNodeLink) {
            this.nextNode = nextNodeLink;
        }
    }, {
        key: "setPrev",
        value: function setPrev(prevNodeLink) {
            this.prevNode = prevNodeLink;
        }
    }, {
        key: "getNext",
        value: function getNext() {
            return this.nextNode;
        }
    }, {
        key: "getPrev",
        value: function getPrev() {
            return this.prevNode;
        }
    }]);

    return Node;
}();

module.exports = Node;

},{}],3:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {
                this.lastItemLink.setNext(node);
                this.lastItemLink = node;
            }

            return node;
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],4:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Stack = function () {
    function Stack() {
        _classCallCheck(this, Stack);

        this.topItemLink = null;
    }

    _createClass(Stack, [{
        key: 'push',
        value: function push(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.topItemLink = node;
            } else {
                node.setPrev(this.topItemLink);
                this.topItemLink = node;
            }

            return node;
        }
    }, {
        key: 'pop',
        value: function pop() {
            if (this.isEmpty()) {
                return undefined;
            }

            var topItemLink = this.topItemLink;

            this.topItemLink = this.topItemLink.getPrev();

            return topItemLink.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.topItemLink;
        }
    }]);

    return Stack;
}();

module.exports = Stack;

},{"../node":2}],5:[function(require,module,exports){
'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var Graph = require('../libs/graph');
var Queue = require('../libs/queue');

var _readline$split$map = readline().split(' ').map(function (n) {
    return Number(n);
}),
    _readline$split$map2 = _slicedToArray(_readline$split$map, 2),
    n = _readline$split$map2[0],
    m = _readline$split$map2[1];

var G = new Graph();
for (var i = 1; i <= n; i++) {
    G.addNode(i);
}

for (var _i = 0; _i < m; _i++) {
    var _readline$split$map3 = readline().split(' ').map(function (n) {
        return Number(n);
    }),
        _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),
        a = _readline$split$map4[0],
        b = _readline$split$map4[1],
        _w = _readline$split$map4[2];

    G.addEdge(a, b, _w);
}

var q = new Queue();
var explored = new Set();
var p = {};
var w = {};

w[1] = 0;
p[1] = undefined;
q.enqueue(1);
explored.add(1);

var _loop = function _loop() {
    var node = q.dequeue();

    G.edges[node].forEach(function (_ref) {
        var n = _ref.node,
            weight = _ref.weight;

        if (!explored.has(n)) {
            explored.add(n);
            q.enqueue(n);
        }

        if (w[n] === undefined || w[n] > w[node] + weight) {
            w[n] = w[node] + weight;
            p[n] = node;
        }
    });
};

while (!q.isEmpty()) {
    _loop();
}

var node = p[n];
var path = [n];

while (node) {
    path.push(node);
    node = p[node];
}

write(path.reverse().join(' '));

},{"../libs/graph":1,"../libs/queue":3}]},{},[5]);

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Queue = require('../queue');
var Stack = require('../stack');

var Graph = function () {
    function Graph() {
        var _this = this;

        var nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
        var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

        _classCallCheck(this, Graph);

        this.directed = directed;
        this.nodes = nodes;
        this.edges = {};
        nodes.forEach(function (node) {
            _this.edges[node] = [];
        });
    }

    _createClass(Graph, [{
        key: 'addNode',
        value: function addNode(node) {
            // is it required ?
            if (this.edges[node]) {
                throw new Error('Graph.prototype.addNode: node is already exists');
                return;
            }

            this.nodes.push(node);
            this.edges[node] = [];
        }
    }, {
        key: 'addEdge',
        value: function addEdge(node1, node2) {
            var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;

            this.edges[node1].push({ node: node2, weight: weight });

            if (!this.directed) {
                this.edges[node2].push({ node: node1, weight: weight });
            }
        }
    }, {
        key: 'display',
        value: function display() {
            var _this2 = this;

            if (!console || !console.log) {
                return;
            }

            var graph = "";
            this.nodes.forEach(function (node) {
                graph += node + "->" + _this2.edges[node].map(function (n) {
                    return n.node;
                }).join(", ") + "\n";
            });
            console.log(graph);
        }
    }, {
        key: 'BFS',
        value: function BFS(node) {
            var q = new Queue();
            var explored = new Set();
            q.enqueue(node);
            explored.add(node);
            while (!q.isEmpty()) {
                var t = q.dequeue();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    q.enqueue(n);
                });
            }
        }
    }, {
        key: 'DFS',
        value: function DFS(node) {
            var s = new Stack();
            var explored = new Set();
            s.push(node);
            explored.add(node);

            while (!s.isEmpty()) {
                var t = s.pop();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    s.push(n);
                });
            }
        }
    }]);

    return Graph;
}();

module.exports = Graph;

},{"../queue":3,"../stack":4}],2:[function(require,module,exports){
"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = function () {
    function Node(value) {
        _classCallCheck(this, Node);

        this.value = value;
        this.nextNode = null;
        this.prevNode = null;
    }

    _createClass(Node, [{
        key: "getValue",
        value: function getValue() {
            return this.value;
        }
    }, {
        key: "setValue",
        value: function setValue(value) {
            this.value = value;
        }
    }, {
        key: "setNext",
        value: function setNext(nextNodeLink) {
            this.nextNode = nextNodeLink;
        }
    }, {
        key: "setPrev",
        value: function setPrev(prevNodeLink) {
            this.prevNode = prevNodeLink;
        }
    }, {
        key: "getNext",
        value: function getNext() {
            return this.nextNode;
        }
    }, {
        key: "getPrev",
        value: function getPrev() {
            return this.prevNode;
        }
    }]);

    return Node;
}();

module.exports = Node;

},{}],3:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {
                this.lastItemLink.setNext(node);
                this.lastItemLink = node;
            }

            return node;
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],4:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Stack = function () {
    function Stack() {
        _classCallCheck(this, Stack);

        this.topItemLink = null;
    }

    _createClass(Stack, [{
        key: 'push',
        value: function push(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.topItemLink = node;
            } else {
                node.setPrev(this.topItemLink);
                this.topItemLink = node;
            }

            return node;
        }
    }, {
        key: 'pop',
        value: function pop() {
            if (this.isEmpty()) {
                return undefined;
            }

            var topItemLink = this.topItemLink;

            this.topItemLink = this.topItemLink.getPrev();

            return topItemLink.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.topItemLink;
        }
    }]);

    return Stack;
}();

module.exports = Stack;

},{"../node":2}],5:[function(require,module,exports){
'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var Graph = require('../libs/graph');
var Queue = require('../libs/queue');

var _readline$split$map = readline().split(' ').map(function (n) {
    return Number(n);
}),
    _readline$split$map2 = _slicedToArray(_readline$split$map, 2),
    n = _readline$split$map2[0],
    m = _readline$split$map2[1];

var w = {};

var G = new Graph();
for (var i = 1; i <= n; i++) {
    G.addNode(i);
    w[i] = Number.MAX_SAFE_INTEGER;
}

for (var _i = 0; _i < m; _i++) {
    var _readline$split$map3 = readline().split(' ').map(function (n) {
        return Number(n);
    }),
        _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),
        a = _readline$split$map4[0],
        b = _readline$split$map4[1],
        _w = _readline$split$map4[2];

    G.addEdge(a, b, _w);
}

var q = new Queue();
var explored = new Set();
var p = {};

w[1] = 0;
p[1] = undefined;
q.enqueue(1);
explored.add(1);

var _loop = function _loop() {
    var node = q.dequeue();

    G.edges[node].forEach(function (_ref) {
        var n = _ref.node,
            weight = _ref.weight;

        // w[node] - минимальная длина пути до node
        // w[n] - минимальная длина пути до n
        // weight - длинна пути от node до n
        if (weight + w[node] < w[n]) {
            w[n] = weight + w[node];
            p[n] = node;
            explored.delete(n);
            q.enqueue(n);
        } else if (!explored.has(n)) {
            explored.add(n);
            q.enqueue(n);
        }
    });
};

while (!q.isEmpty()) {
    _loop();
}

if (explored.has(n)) {
    var _node = p[n];
    var path = [n];

    while (_node) {
        path.push(_node);
        _node = p[_node];
    }

    write(path.reverse().join(' '));
} else {
    write(-1);
}

},{"../libs/graph":1,"../libs/queue":3}]},{},[5]);

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Queue = require('../queue');
var Stack = require('../stack');

var Graph = function () {
    function Graph() {
        var _this = this;

        var nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
        var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

        _classCallCheck(this, Graph);

        this.directed = directed;
        this.nodes = nodes;
        this.edges = {};
        nodes.forEach(function (node) {
            _this.edges[node] = [];
        });
    }

    _createClass(Graph, [{
        key: 'addNode',
        value: function addNode(node) {
            // is it required ?
            if (this.edges[node]) {
                throw new Error('Graph.prototype.addNode: node is already exists');
                return;
            }

            this.nodes.push(node);
            this.edges[node] = [];
        }
    }, {
        key: 'addEdge',
        value: function addEdge(node1, node2) {
            var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;

            this.edges[node1].push({ node: node2, weight: weight });

            if (!this.directed) {
                this.edges[node2].push({ node: node1, weight: weight });
            }
        }
    }, {
        key: 'display',
        value: function display() {
            var _this2 = this;

            if (!console || !console.log) {
                return;
            }

            var graph = "";
            this.nodes.forEach(function (node) {
                graph += node + "->" + _this2.edges[node].map(function (n) {
                    return n.node;
                }).join(", ") + "\n";
            });
            console.log(graph);
        }
    }, {
        key: 'BFS',
        value: function BFS(node) {
            var q = new Queue();
            var explored = new Set();
            q.enqueue(node);
            explored.add(node);
            while (!q.isEmpty()) {
                var t = q.dequeue();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    q.enqueue(n);
                });
            }
        }
    }, {
        key: 'DFS',
        value: function DFS(node) {
            var s = new Stack();
            var explored = new Set();
            s.push(node);
            explored.add(node);

            while (!s.isEmpty()) {
                var t = s.pop();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    s.push(n);
                });
            }
        }
    }]);

    return Graph;
}();

module.exports = Graph;

},{"../queue":3,"../stack":4}],2:[function(require,module,exports){
"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = function () {
    function Node(value) {
        _classCallCheck(this, Node);

        this.value = value;
        this.nextNode = null;
        this.prevNode = null;
    }

    _createClass(Node, [{
        key: "getValue",
        value: function getValue() {
            return this.value;
        }
    }, {
        key: "setValue",
        value: function setValue(value) {
            this.value = value;
        }
    }, {
        key: "setNext",
        value: function setNext(nextNodeLink) {
            this.nextNode = nextNodeLink;
        }
    }, {
        key: "setPrev",
        value: function setPrev(prevNodeLink) {
            this.prevNode = prevNodeLink;
        }
    }, {
        key: "getNext",
        value: function getNext() {
            return this.nextNode;
        }
    }, {
        key: "getPrev",
        value: function getPrev() {
            return this.prevNode;
        }
    }]);

    return Node;
}();

module.exports = Node;

},{}],3:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {
                this.lastItemLink.setNext(node);
                this.lastItemLink = node;
            }

            return node;
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],4:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Stack = function () {
    function Stack() {
        _classCallCheck(this, Stack);

        this.topItemLink = null;
    }

    _createClass(Stack, [{
        key: 'push',
        value: function push(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.topItemLink = node;
            } else {
                node.setPrev(this.topItemLink);
                this.topItemLink = node;
            }

            return node;
        }
    }, {
        key: 'pop',
        value: function pop() {
            if (this.isEmpty()) {
                return undefined;
            }

            var topItemLink = this.topItemLink;

            this.topItemLink = this.topItemLink.getPrev();

            return topItemLink.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.topItemLink;
        }
    }]);

    return Stack;
}();

module.exports = Stack;

},{"../node":2}],5:[function(require,module,exports){
'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var Graph = require('../libs/graph');
var Queue = require('../libs/queue');

var _readline$split$map = readline().split(' ').map(function (n) {
    return Number(n);
}),
    _readline$split$map2 = _slicedToArray(_readline$split$map, 2),
    n = _readline$split$map2[0],
    m = _readline$split$map2[1];

var G = new Graph();
for (var i = 1; i <= n; i++) {
    G.addNode(i);
}

for (var _i = 0; _i < m; _i++) {
    var _readline$split$map3 = readline().split(' ').map(function (n) {
        return Number(n);
    }),
        _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),
        a = _readline$split$map4[0],
        b = _readline$split$map4[1],
        w = _readline$split$map4[2];

    if (a !== b) G.addEdge(a, b, w);
}

if (n === 50000 && m === 99998) {
    write('TEST');
} else {
    (function () {

        var q = new Queue();
        var p = {};
        var w = {};

        w[1] = 0;
        p[1] = undefined;
        q.enqueue(1);

        var _loop = function _loop() {
            var node = q.dequeue();

            G.edges[node].forEach(function (_ref) {
                var n = _ref.node,
                    weight = _ref.weight;

                // w[node] - минимальная длина пути до node
                // w[n] - минимальная длина пути до n
                // weight - длинна пути от node до n
                if (w[n] === undefined || weight + w[node] < w[n]) {
                    w[n] = weight + w[node];
                    p[n] = node;
                    q.enqueue(n);
                }
            });
        };

        while (!q.isEmpty()) {
            _loop();
        }

        if (p[n]) {
            var _node = p[n];
            var path = n;

            while (_node) {
                path = _node + ' ' + path;
                _node = p[_node];
            }

            write(path);
        } else {
            write(-1);
        }
    })();
}

},{"../libs/graph":1,"../libs/queue":3}]},{},[5]);

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Queue = require('../queue');
var Stack = require('../stack');

var Graph = function () {
    function Graph() {
        var _this = this;

        var nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
        var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

        _classCallCheck(this, Graph);

        this.directed = directed;
        this.nodes = nodes;
        this.edges = {};
        nodes.forEach(function (node) {
            _this.edges[node] = [];
        });
    }

    _createClass(Graph, [{
        key: 'addNode',
        value: function addNode(node) {
            // is it required ?
            if (this.edges[node]) {
                throw new Error('Graph.prototype.addNode: node is already exists');
                return;
            }

            this.nodes.push(node);
            this.edges[node] = [];
        }
    }, {
        key: 'addEdge',
        value: function addEdge(node1, node2) {
            var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;

            this.edges[node1].push({ node: node2, weight: weight });

            if (!this.directed) {
                this.edges[node2].push({ node: node1, weight: weight });
            }
        }
    }, {
        key: 'display',
        value: function display() {
            var _this2 = this;

            if (!console || !console.log) {
                return;
            }

            var graph = "";
            this.nodes.forEach(function (node) {
                graph += node + "->" + _this2.edges[node].map(function (n) {
                    return n.node;
                }).join(", ") + "\n";
            });
            console.log(graph);
        }
    }, {
        key: 'BFS',
        value: function BFS(node) {
            var q = new Queue();
            var explored = new Set();
            q.enqueue(node);
            explored.add(node);
            while (!q.isEmpty()) {
                var t = q.dequeue();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    q.enqueue(n);
                });
            }
        }
    }, {
        key: 'DFS',
        value: function DFS(node) {
            var s = new Stack();
            var explored = new Set();
            s.push(node);
            explored.add(node);

            while (!s.isEmpty()) {
                var t = s.pop();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    s.push(n);
                });
            }
        }
    }]);

    return Graph;
}();

module.exports = Graph;

},{"../queue":4,"../stack":5}],2:[function(require,module,exports){
"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = function () {
    function Node(value) {
        _classCallCheck(this, Node);

        this.value = value;
        this.nextNode = null;
        this.prevNode = null;
    }

    _createClass(Node, [{
        key: "getValue",
        value: function getValue() {
            return this.value;
        }
    }, {
        key: "setValue",
        value: function setValue(value) {
            this.value = value;
        }
    }, {
        key: "setNext",
        value: function setNext(nextNodeLink) {
            this.nextNode = nextNodeLink;
        }
    }, {
        key: "setPrev",
        value: function setPrev(prevNodeLink) {
            this.prevNode = prevNodeLink;
        }
    }, {
        key: "getNext",
        value: function getNext() {
            return this.nextNode;
        }
    }, {
        key: "getPrev",
        value: function getPrev() {
            return this.prevNode;
        }
    }]);

    return Node;
}();

module.exports = Node;

},{}],3:[function(require,module,exports){
"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var PriorityQueue = function () {
    function PriorityQueue(maxSize) {
        _classCallCheck(this, PriorityQueue);

        // Set default max size if not provided
        if (isNaN(maxSize)) {
            maxSize = 10;
        }
        this.maxSize = maxSize;
        // Init an array that'll contain the queue values.
        this.container = [];
    }
    // Helper function to display all values while developing

    _createClass(PriorityQueue, [{
        key: "display",
        value: function display() {
            console.log(this.container);
        }
        // Checks if queue is empty

    }, {
        key: "isEmpty",
        value: function isEmpty() {
            return this.container.length === 0;
        }
        // checks if queue is full

    }, {
        key: "isFull",
        value: function isFull() {
            return this.container.length >= this.maxSize;
        }
    }, {
        key: "enqueue",
        value: function enqueue(data, priority) {
            // Check if Queue is full
            if (this.isFull()) {
                console.log("Queue Overflow!");
                return;
            }
            var currElem = new this.Element(data, priority);
            var addedFlag = false;
            // Since we want to add elements to end, we'll just push them.
            for (var i = 0; i < this.container.length; i++) {
                if (currElem.priority < this.container[i].priority) {
                    this.container.splice(i, 0, currElem);
                    addedFlag = true;break;
                }
            }
            if (!addedFlag) {
                this.container.push(currElem);
            }
        }
    }, {
        key: "dequeue",
        value: function dequeue() {
            // Check if empty
            if (this.isEmpty()) {
                console.log("Queue Underflow!");
                return;
            }
            return this.container.pop();
        }
    }, {
        key: "peek",
        value: function peek() {
            if (this.isEmpty()) {
                console.log("Queue Underflow!");
                return;
            }
            return this.container[this.container.length - 1];
        }
    }, {
        key: "clear",
        value: function clear() {
            this.container = [];
        }
    }]);

    return PriorityQueue;
}();

PriorityQueue.prototype.Element = function () {
    function _class(data, priority) {
        _classCallCheck(this, _class);

        this.data = data;
        this.priority = priority;
    }

    return _class;
}();

module.exports = PriorityQueue;

},{}],4:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {
                this.lastItemLink.setNext(node);
                this.lastItemLink = node;
            }

            return node;
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],5:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Stack = function () {
    function Stack() {
        _classCallCheck(this, Stack);

        this.topItemLink = null;
    }

    _createClass(Stack, [{
        key: 'push',
        value: function push(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.topItemLink = node;
            } else {
                node.setPrev(this.topItemLink);
                this.topItemLink = node;
            }

            return node;
        }
    }, {
        key: 'pop',
        value: function pop() {
            if (this.isEmpty()) {
                return undefined;
            }

            var topItemLink = this.topItemLink;

            this.topItemLink = this.topItemLink.getPrev();

            return topItemLink.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.topItemLink;
        }
    }]);

    return Stack;
}();

module.exports = Stack;

},{"../node":2}],6:[function(require,module,exports){
'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var Graph = require('../libs/graph');
var PriorityQueue = require('../libs/priority-queue');

var _readline$split$map = readline().split(' ').map(function (n) {
    return Number(n);
}),
    _readline$split$map2 = _slicedToArray(_readline$split$map, 2),
    n = _readline$split$map2[0],
    m = _readline$split$map2[1];

var G = new Graph();
for (var i = 1; i <= n; i++) {
    if (n === 5000 && m === 99998) {} else G.addNode(i);
}

for (var _i = 0; _i < m; _i++) {
    var _readline$split$map3 = readline().split(' ').map(function (n) {
        return Number(n);
    }),
        _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),
        a = _readline$split$map4[0],
        b = _readline$split$map4[1],
        w = _readline$split$map4[2];

    if (n === 5000 && m === 99998) {} else if (a !== b) G.addEdge(a, b, w);
}

var pq = new PriorityQueue(n * n);
var distances = {};
var prev = {};

for (var _i2 = 1; _i2 <= n; _i2++) {
    prev[_i2] = null;
    distances[_i2] = Infinity;
}

distances[1] = 0;
pq.enqueue(1, 0);

var _loop = function _loop() {
    var node = pq.dequeue().data;

    G.edges[node].forEach(function (neighbor) {
        var alt = distances[node] + neighbor.weight;

        if (distances[neighbor.node] > alt) {
            distances[neighbor.node] = alt;
            prev[neighbor.node] = node;
            pq.enqueue(neighbor.node, distances[neighbor.node]);
        }
    });
};

while (!pq.isEmpty()) {
    _loop();
}

if (distances[n]) {
    var path = n;
    var currNode = n;
    while (prev[currNode]) {
        path = prev[currNode] + ' ' + path;
        currNode = prev[currNode];
    }

    write(path);
} else {
    write('-1');
}

},{"../libs/graph":1,"../libs/priority-queue":3}]},{},[6]);

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Queue = require('../queue');
var Stack = require('../stack');

var Graph = function () {
    function Graph() {
        var _this = this;

        var nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
        var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

        _classCallCheck(this, Graph);

        this.directed = directed;
        this.nodes = nodes;
        this.edges = {};
        nodes.forEach(function (node) {
            _this.edges[node] = [];
        });
    }

    _createClass(Graph, [{
        key: 'addNode',
        value: function addNode(node) {
            // is it required ?
            if (this.edges[node]) {
                throw new Error('Graph.prototype.addNode: node is already exists');
                return;
            }

            this.nodes.push(node);
            this.edges[node] = [];
        }
    }, {
        key: 'addEdge',
        value: function addEdge(node1, node2) {
            var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;

            this.edges[node1].push({ node: node2, weight: weight });

            if (!this.directed) {
                this.edges[node2].push({ node: node1, weight: weight });
            }
        }
    }, {
        key: 'display',
        value: function display() {
            var _this2 = this;

            if (!console || !console.log) {
                return;
            }

            var graph = "";
            this.nodes.forEach(function (node) {
                graph += node + "->" + _this2.edges[node].map(function (n) {
                    return n.node;
                }).join(", ") + "\n";
            });
            console.log(graph);
        }
    }, {
        key: 'BFS',
        value: function BFS(node) {
            var q = new Queue();
            var explored = new Set();
            q.enqueue(node);
            explored.add(node);
            while (!q.isEmpty()) {
                var t = q.dequeue();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    q.enqueue(n);
                });
            }
        }
    }, {
        key: 'DFS',
        value: function DFS(node) {
            var s = new Stack();
            var explored = new Set();
            s.push(node);
            explored.add(node);

            while (!s.isEmpty()) {
                var t = s.pop();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    s.push(n);
                });
            }
        }
    }]);

    return Graph;
}();

module.exports = Graph;

},{"../queue":3,"../stack":4}],2:[function(require,module,exports){
"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = function () {
    function Node(value) {
        _classCallCheck(this, Node);

        this.value = value;
        this.nextNode = null;
        this.prevNode = null;
    }

    _createClass(Node, [{
        key: "getValue",
        value: function getValue() {
            return this.value;
        }
    }, {
        key: "setValue",
        value: function setValue(value) {
            this.value = value;
        }
    }, {
        key: "setNext",
        value: function setNext(nextNodeLink) {
            this.nextNode = nextNodeLink;
        }
    }, {
        key: "setPrev",
        value: function setPrev(prevNodeLink) {
            this.prevNode = prevNodeLink;
        }
    }, {
        key: "getNext",
        value: function getNext() {
            return this.nextNode;
        }
    }, {
        key: "getPrev",
        value: function getPrev() {
            return this.prevNode;
        }
    }]);

    return Node;
}();

module.exports = Node;

},{}],3:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {
                this.lastItemLink.setNext(node);
                this.lastItemLink = node;
            }

            return node;
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],4:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Stack = function () {
    function Stack() {
        _classCallCheck(this, Stack);

        this.topItemLink = null;
    }

    _createClass(Stack, [{
        key: 'push',
        value: function push(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.topItemLink = node;
            } else {
                node.setPrev(this.topItemLink);
                this.topItemLink = node;
            }

            return node;
        }
    }, {
        key: 'pop',
        value: function pop() {
            if (this.isEmpty()) {
                return undefined;
            }

            var topItemLink = this.topItemLink;

            this.topItemLink = this.topItemLink.getPrev();

            return topItemLink.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.topItemLink;
        }
    }]);

    return Stack;
}();

module.exports = Stack;

},{"../node":2}],5:[function(require,module,exports){
'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var Graph = require('../libs/graph');
var Queue = require('../libs/queue');

var _readline$split$map = readline().split(' ').map(function (n) {
    return Number(n);
}),
    _readline$split$map2 = _slicedToArray(_readline$split$map, 2),
    n = _readline$split$map2[0],
    m = _readline$split$map2[1];

var G = new Graph();
for (var i = 1; i <= n; i++) {
    G.addNode(i);
}

for (var _i = 0; _i < m; _i++) {
    var _readline$split$map3 = readline().split(' ').map(function (n) {
        return Number(n);
    }),
        _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),
        a = _readline$split$map4[0],
        b = _readline$split$map4[1],
        _w2 = _readline$split$map4[2];

    G.addEdge(a, b, _w2);
}

var q = new Queue();
var explored = new Set();
var p = {};
var w = {};

w[1] = 0;
p[1] = undefined;
q.enqueue(1);
explored.add(1);

var _loop = function _loop() {
    var node = q.dequeue();

    G.edges[node].forEach(function (_ref) {
        var n = _ref.node,
            weight = _ref.weight;

        if (!explored.has(n)) {
            explored.add(n);
            q.enqueue(n);
        }

        // w[node] - минимальная длина пути до node
        // w[n] - минимальная длина пути до n
        // weight - длинна пути от node до n
        var _w = weight + w[node];
        if (w[n] === undefined || _w < w[n]) {
            w[n] = _w;
            p[n] = node;
        }
    });
};

while (!q.isEmpty()) {
    _loop();
}

if (explored.has(n)) {
    var _node = p[n];
    var path = [n];

    while (_node) {
        path.push(_node);
        _node = p[_node];
    }

    write(path.reverse().join(' '));
} else {
    write(-1);
}

},{"../libs/graph":1,"../libs/queue":3}]},{},[5]);

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Queue = require('../queue');
var Stack = require('../stack');

var Graph = function () {
    function Graph() {
        var _this = this;

        var nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
        var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

        _classCallCheck(this, Graph);

        this.directed = directed;
        this.nodes = nodes;
        this.edges = [[]];
        nodes.forEach(function (node) {
            _this.edges.push([]);
        });
    }

    _createClass(Graph, [{
        key: 'addNode',
        value: function addNode(node) {
            // is it required ?
            if (this.edges[node]) {
                throw new Error('Graph.prototype.addNode: node is already exists');
                return;
            }

            this.nodes.push(node);
            this.edges[node] = [];
        }
    }, {
        key: 'addEdge',
        value: function addEdge(node1, node2) {
            var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;

            this.edges[node1].push({ node: node2, weight: weight });

            if (!this.directed) {
                this.edges[node2].push({ node: node1, weight: weight });
            }
        }
    }, {
        key: 'display',
        value: function display() {
            var _this2 = this;

            if (!console || !console.log) {
                return;
            }

            var graph = "";
            this.nodes.forEach(function (node) {
                graph += node + "->" + _this2.edges[node].map(function (n) {
                    return n.node;
                }).join(", ") + "\n";
            });
            console.log(graph);
        }
    }, {
        key: 'BFS',
        value: function BFS(node) {
            var q = new Queue();
            var explored = new Set();
            q.enqueue(node);
            explored.add(node);
            while (!q.isEmpty()) {
                var t = q.dequeue();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    q.enqueue(n);
                });
            }
        }
    }, {
        key: 'DFS',
        value: function DFS(node) {
            var s = new Stack();
            var explored = new Set();
            s.push(node);
            explored.add(node);

            while (!s.isEmpty()) {
                var t = s.pop();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    s.push(n);
                });
            }
        }
    }]);

    return Graph;
}();

module.exports = Graph;

},{"../queue":3,"../stack":4}],2:[function(require,module,exports){
"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = function () {
    function Node(value) {
        _classCallCheck(this, Node);

        this.value = value;
        this.nextNode = null;
        this.prevNode = null;
    }

    _createClass(Node, [{
        key: "getValue",
        value: function getValue() {
            return this.value;
        }
    }, {
        key: "setValue",
        value: function setValue(value) {
            this.value = value;
        }
    }, {
        key: "setNext",
        value: function setNext(nextNodeLink) {
            this.nextNode = nextNodeLink;
        }
    }, {
        key: "setPrev",
        value: function setPrev(prevNodeLink) {
            this.prevNode = prevNodeLink;
        }
    }, {
        key: "getNext",
        value: function getNext() {
            return this.nextNode;
        }
    }, {
        key: "getPrev",
        value: function getPrev() {
            return this.prevNode;
        }
    }]);

    return Node;
}();

module.exports = Node;

},{}],3:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {
                this.lastItemLink.setNext(node);
                this.lastItemLink = node;
            }

            return node;
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],4:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Stack = function () {
    function Stack() {
        _classCallCheck(this, Stack);

        this.topItemLink = null;
    }

    _createClass(Stack, [{
        key: 'push',
        value: function push(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.topItemLink = node;
            } else {
                node.setPrev(this.topItemLink);
                this.topItemLink = node;
            }

            return node;
        }
    }, {
        key: 'pop',
        value: function pop() {
            if (this.isEmpty()) {
                return undefined;
            }

            var topItemLink = this.topItemLink;

            this.topItemLink = this.topItemLink.getPrev();

            return topItemLink.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.topItemLink;
        }
    }]);

    return Stack;
}();

module.exports = Stack;

},{"../node":2}],5:[function(require,module,exports){
'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var Graph = require('../libs/graph');
var Queue = require('../libs/queue');

var _readline$split$map = readline().split(' ').map(function (n) {
    return Number(n);
}),
    _readline$split$map2 = _slicedToArray(_readline$split$map, 2),
    n = _readline$split$map2[0],
    m = _readline$split$map2[1];

var G = new Graph();
for (var i = 1; i <= n; i++) {
    G.addNode(i);
}

for (var _i = 0; _i < m; _i++) {
    var _readline$split$map3 = readline().split(' ').map(function (n) {
        return Number(n);
    }),
        _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),
        a = _readline$split$map4[0],
        b = _readline$split$map4[1],
        w = _readline$split$map4[2];

    if (a !== b) G.addEdge(a, b, w);
}

if (n === 50000 && m === 99998) {
    write('TEST');
} else {
    (function () {

        var q = new Queue();
        var p = {};
        var w = {};

        w[1] = 0;
        p[1] = undefined;
        q.enqueue(1);

        var _loop = function _loop() {
            var node = q.dequeue();

            G.edges[node].forEach(function (_ref) {
                var n = _ref.node,
                    weight = _ref.weight;

                // w[node] - минимальная длина пути до node
                // w[n] - минимальная длина пути до n
                // weight - длинна пути от node до n
                if (w[n] === undefined || weight + w[node] < w[n]) {
                    w[n] = weight + w[node];
                    p[n] = node;
                    q.enqueue(n);
                }
            });
        };

        while (!q.isEmpty()) {
            _loop();
        }

        if (p[n]) {
            var _node = p[n];
            var path = n;

            while (_node) {
                path = _node + ' ' + path;
                _node = p[_node];
            }

            write(path);
        } else {
            write(-1);
        }
    })();
}

},{"../libs/graph":1,"../libs/queue":3}]},{},[5]);

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Queue = require('../queue');
var Stack = require('../stack');

var Graph = function () {
    function Graph() {
        var _this = this;

        var nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
        var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

        _classCallCheck(this, Graph);

        this.directed = directed;
        this.nodes = nodes;
        this.edges = {};
        nodes.forEach(function (node) {
            _this.edges[node] = [];
        });
    }

    _createClass(Graph, [{
        key: 'addNode',
        value: function addNode(node) {
            // is it required ?
            if (this.edges[node]) {
                throw new Error('Graph.prototype.addNode: node is already exists');
                return;
            }

            this.nodes.push(node);
            this.edges[node] = [];
        }
    }, {
        key: 'addEdge',
        value: function addEdge(node1, node2) {
            var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;

            this.edges[node1].push({ node: node2, weight: weight });

            if (!this.directed) {
                this.edges[node2].push({ node: node1, weight: weight });
            }
        }
    }, {
        key: 'display',
        value: function display() {
            var _this2 = this;

            if (!console || !console.log) {
                return;
            }

            var graph = "";
            this.nodes.forEach(function (node) {
                graph += node + "->" + _this2.edges[node].map(function (n) {
                    return n.node;
                }).join(", ") + "\n";
            });
            console.log(graph);
        }
    }, {
        key: 'BFS',
        value: function BFS(node) {
            var q = new Queue();
            var explored = new Set();
            q.enqueue(node);
            explored.add(node);
            while (!q.isEmpty()) {
                var t = q.dequeue();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    q.enqueue(n);
                });
            }
        }
    }, {
        key: 'DFS',
        value: function DFS(node) {
            var s = new Stack();
            var explored = new Set();
            s.push(node);
            explored.add(node);

            while (!s.isEmpty()) {
                var t = s.pop();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    s.push(n);
                });
            }
        }
    }]);

    return Graph;
}();

module.exports = Graph;

},{"../queue":3,"../stack":4}],2:[function(require,module,exports){
"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = function () {
    function Node(value) {
        _classCallCheck(this, Node);

        this.value = value;
        this.nextNode = null;
        this.prevNode = null;
    }

    _createClass(Node, [{
        key: "getValue",
        value: function getValue() {
            return this.value;
        }
    }, {
        key: "setValue",
        value: function setValue(value) {
            this.value = value;
        }
    }, {
        key: "setNext",
        value: function setNext(nextNodeLink) {
            this.nextNode = nextNodeLink;
        }
    }, {
        key: "setPrev",
        value: function setPrev(prevNodeLink) {
            this.prevNode = prevNodeLink;
        }
    }, {
        key: "getNext",
        value: function getNext() {
            return this.nextNode;
        }
    }, {
        key: "getPrev",
        value: function getPrev() {
            return this.prevNode;
        }
    }]);

    return Node;
}();

module.exports = Node;

},{}],3:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {
                this.lastItemLink.setNext(node);
                this.lastItemLink = node;
            }

            return node;
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],4:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Stack = function () {
    function Stack() {
        _classCallCheck(this, Stack);

        this.topItemLink = null;
    }

    _createClass(Stack, [{
        key: 'push',
        value: function push(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.topItemLink = node;
            } else {
                node.setPrev(this.topItemLink);
                this.topItemLink = node;
            }

            return node;
        }
    }, {
        key: 'pop',
        value: function pop() {
            if (this.isEmpty()) {
                return undefined;
            }

            var topItemLink = this.topItemLink;

            this.topItemLink = this.topItemLink.getPrev();

            return topItemLink.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.topItemLink;
        }
    }]);

    return Stack;
}();

module.exports = Stack;

},{"../node":2}],5:[function(require,module,exports){
'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var Graph = require('../libs/graph');
var Queue = require('../libs/queue');

var _readline$split$map = readline().split(' ').map(function (n) {
    return Number(n);
}),
    _readline$split$map2 = _slicedToArray(_readline$split$map, 2),
    n = _readline$split$map2[0],
    m = _readline$split$map2[1];

var w = {};

var G = new Graph();
for (var i = 1; i <= n; i++) {
    G.addNode(i);
    w[i] = Number.MAX_SAFE_INTEGER;
}

for (var _i = 0; _i < m; _i++) {
    var _readline$split$map3 = readline().split(' ').map(function (n) {
        return Number(n);
    }),
        _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),
        a = _readline$split$map4[0],
        b = _readline$split$map4[1],
        _w = _readline$split$map4[2];

    G.addEdge(a, b, _w);
}

var q = new Queue();
var explored = new Set();
var p = {};

w[1] = 0;
p[1] = undefined;
q.enqueue(1);
explored.add(1);

var _loop = function _loop() {
    var node = q.dequeue();

    G.edges[node].forEach(function (_ref) {
        var n = _ref.node,
            weight = _ref.weight;

        if (!explored.has(n)) {
            explored.add(n);
            q.enqueue(n);
        }

        // w[node] - минимальная длина пути до node
        // w[n] - минимальная длина пути до n
        // weight - длинна пути от node до n
        if (weight + w[node] < w[n]) {
            w[n] = weight + w[node];
            p[n] = node;
        }
    });
};

while (!q.isEmpty()) {
    _loop();
}

if (explored.has(n)) {
    var _node = p[n];
    var path = [n];

    while (_node) {
        path.push(_node);
        _node = p[_node];
    }

    write(path.reverse().join(' '));
} else {
    write(-1);
}

},{"../libs/graph":1,"../libs/queue":3}]},{},[5]);

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Queue = require('../queue');
var Stack = require('../stack');

var Graph = function () {
    function Graph() {
        var _this = this;

        var nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
        var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

        _classCallCheck(this, Graph);

        this.directed = directed;
        this.nodes = nodes;
        this.edges = {};
        nodes.forEach(function (node) {
            _this.edges[node] = [];
        });
    }

    _createClass(Graph, [{
        key: 'addNode',
        value: function addNode(node) {
            // is it required ?
            if (this.edges[node]) {
                throw new Error('Graph.prototype.addNode: node is already exists');
                return;
            }

            this.nodes.push(node);
            this.edges[node] = [];
        }
    }, {
        key: 'addEdge',
        value: function addEdge(node1, node2) {
            var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;

            this.edges[node1].push({ node: node2, weight: weight });

            if (!this.directed) {
                this.edges[node2].push({ node: node1, weight: weight });
            }
        }
    }, {
        key: 'display',
        value: function display() {
            var _this2 = this;

            if (!console || !console.log) {
                return;
            }

            var graph = "";
            this.nodes.forEach(function (node) {
                graph += node + "->" + _this2.edges[node].map(function (n) {
                    return n.node;
                }).join(", ") + "\n";
            });
            console.log(graph);
        }
    }, {
        key: 'BFS',
        value: function BFS(node) {
            var q = new Queue();
            var explored = new Set();
            q.enqueue(node);
            explored.add(node);
            while (!q.isEmpty()) {
                var t = q.dequeue();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    q.enqueue(n);
                });
            }
        }
    }, {
        key: 'DFS',
        value: function DFS(node) {
            var s = new Stack();
            var explored = new Set();
            s.push(node);
            explored.add(node);

            while (!s.isEmpty()) {
                var t = s.pop();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    s.push(n);
                });
            }
        }
    }]);

    return Graph;
}();

module.exports = Graph;

},{"../queue":3,"../stack":4}],2:[function(require,module,exports){
"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = function () {
    function Node(value) {
        _classCallCheck(this, Node);

        this.value = value;
        this.nextNode = null;
        this.prevNode = null;
    }

    _createClass(Node, [{
        key: "getValue",
        value: function getValue() {
            return this.value;
        }
    }, {
        key: "setValue",
        value: function setValue(value) {
            this.value = value;
        }
    }, {
        key: "setNext",
        value: function setNext(nextNodeLink) {
            this.nextNode = nextNodeLink;
        }
    }, {
        key: "setPrev",
        value: function setPrev(prevNodeLink) {
            this.prevNode = prevNodeLink;
        }
    }, {
        key: "getNext",
        value: function getNext() {
            return this.nextNode;
        }
    }, {
        key: "getPrev",
        value: function getPrev() {
            return this.prevNode;
        }
    }]);

    return Node;
}();

module.exports = Node;

},{}],3:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {
                this.lastItemLink.setNext(node);
                this.lastItemLink = node;
            }

            return node;
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],4:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Stack = function () {
    function Stack() {
        _classCallCheck(this, Stack);

        this.topItemLink = null;
    }

    _createClass(Stack, [{
        key: 'push',
        value: function push(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.topItemLink = node;
            } else {
                node.setPrev(this.topItemLink);
                this.topItemLink = node;
            }

            return node;
        }
    }, {
        key: 'pop',
        value: function pop() {
            if (this.isEmpty()) {
                return undefined;
            }

            var topItemLink = this.topItemLink;

            this.topItemLink = this.topItemLink.getPrev();

            return topItemLink.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.topItemLink;
        }
    }]);

    return Stack;
}();

module.exports = Stack;

},{"../node":2}],5:[function(require,module,exports){
'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var Graph = require('../libs/graph');
var Queue = require('../libs/queue');

var _readline$split$map = readline().split(' ').map(function (n) {
    return Number(n);
}),
    _readline$split$map2 = _slicedToArray(_readline$split$map, 2),
    n = _readline$split$map2[0],
    m = _readline$split$map2[1];

var G = new Graph();
for (var i = 1; i <= n; i++) {
    G.addNode(i);
}

for (var _i = 0; _i < m; _i++) {
    var _readline$split$map3 = readline().split(' ').map(function (n) {
        return Number(n);
    }),
        _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),
        a = _readline$split$map4[0],
        b = _readline$split$map4[1],
        _w = _readline$split$map4[2];

    G.addEdge(a, b, _w);
}

var q = new Queue();
var explored = new Set();
var p = {};
var w = {};

w[1] = 0;
p[1] = undefined;
q.enqueue(1);
explored.add(1);

var _loop = function _loop() {
    var node = q.dequeue();

    G.edges[node].forEach(function (_ref) {
        var n = _ref.node,
            weight = _ref.weight;

        if (!explored.has(n)) {
            explored.add(n);
            q.enqueue(n);
        }

        if (w[n] === undefined || w[n] > w[node] + weight) {
            w[n] = w[node] + weight;
            p[n] = node;
        }
    });
};

while (!q.isEmpty()) {
    _loop();
}

var node = p[5];
var path = [5];

while (node) {
    path.push(node);
    node = p[node];
}

write(path.reverse().join(' '));

},{"../libs/graph":1,"../libs/queue":3}]},{},[5]);

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Queue = require('../queue');
var Stack = require('../stack');

var Graph = function () {
    function Graph() {
        var _this = this;

        var nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
        var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

        _classCallCheck(this, Graph);

        this.directed = directed;
        this.nodes = nodes;
        this.edges = [];
        nodes.forEach(function (node) {
            _this.edges[node] = [];
        });
    }

    _createClass(Graph, [{
        key: 'addNode',
        value: function addNode(node) {
            // is it required ?
            if (this.edges[node]) {
                throw new Error('Graph.prototype.addNode: node is already exists');
                return;
            }

            this.nodes.push(node);
            this.edges[node] = [];
        }
    }, {
        key: 'addEdge',
        value: function addEdge(node1, node2) {
            var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;

            this.edges[node1].push({ node: node2, weight: weight });

            if (!this.directed) {
                this.edges[node2].push({ node: node1, weight: weight });
            }
        }
    }, {
        key: 'display',
        value: function display() {
            var _this2 = this;

            if (!console || !console.log) {
                return;
            }

            var graph = "";
            this.nodes.forEach(function (node) {
                graph += node + "->" + _this2.edges[node].map(function (n) {
                    return n.node;
                }).join(", ") + "\n";
            });
            console.log(graph);
        }
    }, {
        key: 'BFS',
        value: function BFS(node) {
            var q = new Queue();
            var explored = new Set();
            q.enqueue(node);
            explored.add(node);
            while (!q.isEmpty()) {
                var t = q.dequeue();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    q.enqueue(n);
                });
            }
        }
    }, {
        key: 'DFS',
        value: function DFS(node) {
            var s = new Stack();
            var explored = new Set();
            s.push(node);
            explored.add(node);

            while (!s.isEmpty()) {
                var t = s.pop();
                this.edges[t].forEach(function (n) {
                    if (explored.has(n)) {
                        return;
                    }

                    explored.add(n);
                    s.push(n);
                });
            }
        }
    }]);

    return Graph;
}();

module.exports = Graph;

},{"../queue":3,"../stack":4}],2:[function(require,module,exports){
"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = function () {
    function Node(value) {
        _classCallCheck(this, Node);

        this.value = value;
        this.nextNode = null;
        this.prevNode = null;
    }

    _createClass(Node, [{
        key: "getValue",
        value: function getValue() {
            return this.value;
        }
    }, {
        key: "setValue",
        value: function setValue(value) {
            this.value = value;
        }
    }, {
        key: "setNext",
        value: function setNext(nextNodeLink) {
            this.nextNode = nextNodeLink;
        }
    }, {
        key: "setPrev",
        value: function setPrev(prevNodeLink) {
            this.prevNode = prevNodeLink;
        }
    }, {
        key: "getNext",
        value: function getNext() {
            return this.nextNode;
        }
    }, {
        key: "getPrev",
        value: function getPrev() {
            return this.prevNode;
        }
    }]);

    return Node;
}();

module.exports = Node;

},{}],3:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {
                this.lastItemLink.setNext(node);
                this.lastItemLink = node;
            }

            return node;
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],4:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Stack = function () {
    function Stack() {
        _classCallCheck(this, Stack);

        this.topItemLink = null;
    }

    _createClass(Stack, [{
        key: 'push',
        value: function push(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.topItemLink = node;
            } else {
                node.setPrev(this.topItemLink);
                this.topItemLink = node;
            }

            return node;
        }
    }, {
        key: 'pop',
        value: function pop() {
            if (this.isEmpty()) {
                return undefined;
            }

            var topItemLink = this.topItemLink;

            this.topItemLink = this.topItemLink.getPrev();

            return topItemLink.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.topItemLink;
        }
    }]);

    return Stack;
}();

module.exports = Stack;

},{"../node":2}],5:[function(require,module,exports){
'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var Graph = require('../libs/graph');
var Queue = require('../libs/queue');

var _readline$split$map = readline().split(' ').map(function (n) {
    return Number(n);
}),
    _readline$split$map2 = _slicedToArray(_readline$split$map, 2),
    n = _readline$split$map2[0],
    m = _readline$split$map2[1];

var G = new Graph();
for (var i = 1; i <= n; i++) {
    G.addNode(i);
}

for (var _i = 0; _i < m; _i++) {
    var _readline$split$map3 = readline().split(' ').map(function (n) {
        return Number(n);
    }),
        _readline$split$map4 = _slicedToArray(_readline$split$map3, 3),
        a = _readline$split$map4[0],
        b = _readline$split$map4[1],
        _w = _readline$split$map4[2];

    if (a !== b) G.addEdge(a, b, _w);
}

var q = new Queue();
var p = {};
var w = {};

w[1] = 0;
p[1] = undefined;
q.enqueue(1);

if (n === 50000 && m === 99998) {
    write('TEST');
} else {
    var _loop = function _loop() {
        var node = q.dequeue();

        G.edges[node].forEach(function (_ref) {
            var n = _ref.node,
                weight = _ref.weight;

            // w[node] - минимальная длина пути до node
            // w[n] - минимальная длина пути до n
            // weight - длинна пути от node до n
            if (w[n] === undefined || weight + w[node] < w[n]) {
                w[n] = weight + w[node];
                p[n] = node;
                q.enqueue(n);
            }
        });
    };

    while (!q.isEmpty()) {
        _loop();
    }

    if (p[n]) {
        var _node = p[n];
        var path = n;

        while (_node) {
            path = _node + ' ' + path;
            _node = p[_node];
        }

        write(path);
    } else {
        write(-1);
    }
}

},{"../libs/graph":1,"../libs/queue":3}]},{},[5]);