import java.io.*;
import java.util.*;

public class Main {

	static BufferedReader in;
	static PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	public static void main(String[] args) throws IOException {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
		} catch (Exception e) {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter(new File("output.txt"));
		}
		new Main().solve();
		out.flush();
		out.close();
	}

	void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();
		ArrayList<Edge> g[] = new ArrayList[n+1];
		for (int i = 0; i <= n; i++) {
			g[i] = new ArrayList<>();
		}
		for (int i = 0; i < m; i++) {
			int v = nextInt();
			int to = nextInt();
			int cost = nextInt();
			g[v].add(new Edge(to, cost));
			g[to].add(new Edge(v, cost));
		}

		long[] d = new long[n+1];
		int[] p = new int[n+1];
		long inf = Long.MAX_VALUE;
		Arrays.fill(d, inf);
		//Arrays.fill(p, -1);
		TreeSet<Edge> treeSet = new TreeSet<>();
		treeSet.add(new Edge(1, 0));
		d[1] = 0;

		while (!treeSet.isEmpty()) {
			int v = treeSet.pollFirst().to;

			for (int i = 0; i < g[v].size(); i++) {
				Edge next = g[v].get(i);
				if (next.cost + d[v] < d[next.to]) {
					d[next.to] = next.cost + d[v];
					p[next.to] = v;
					treeSet.add(new Edge(next.to, d[next.to]));
				}
			}
		}

		if (d[n] == inf) {
			out.println(-1);
			return;
		}

		ArrayList<Integer> ans = new ArrayList<>();
		out.print("1 ");
		for (int i = n; i != 1; i = p[i]) {
			ans.add(i);
		}
		for (int i = ans.size()-1; i >= 0; i--) {
			out.print(ans.get(i) + " ");
		}

	}

	String nextTok() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.valueOf(nextTok());
	}

	class Edge implements Comparable<Edge> {
		int to;
		long cost;

		Edge(int to, long cost) {
			this.to = to;
			this.cost = cost;
		}

		public int compareTo(Edge e) {
			return Long.compare(this.cost, e.cost);
		}
	}

}


import java.io.*;
import java.util.*;
public final class alphaRnd20_C
{
	static Scanner sc=new Scanner(System.in);
	static PrintWriter out=new PrintWriter(System.out);
	static ArrayList<Node>[] a;
	static int n,m;
	static long[] dis;
	static int[] prev;

	static void print(int k)
	{
		if(prev[k]!=-1)
		{
			print(prev[k]);
			out.print(k+" ");
		}
	}

	public static void main(String args[]) throws Exception
	{
		n=sc.nextInt();
		m=sc.nextInt();
		a=new ArrayList[n+1];
		dis=new long[n+1];
		prev=new int[n+1];
		for(int i=1;i<=n;i++)
		{
			a[i]=new ArrayList<Node>();
			dis[i]=Long.MAX_VALUE;
			prev[i]=-1;
		}
		for(int i=0;i<m;i++)
		{
			int u=sc.nextInt();
			int v=sc.nextInt();
			long w=sc.nextLong();
			a[u].add(new Node(v,w));
			a[v].add(new Node(u,w));
		}
		PriorityQueue<Node> pq=new PriorityQueue<Node>();
		dis[1]=0;
		pq.add(new Node(1,0));
		while(pq.size()>0)
		{
			Node n1=pq.poll();
			for(Node x:a[n1.val])
			{
				if(dis[x.val]>dis[n1.val]+x.cost)
				{
					dis[x.val]=dis[n1.val]+x.cost;
					pq.add(new Node(x.val,n1.cost+dis[x.val]));
					prev[x.val]=n1.val;
				}
			}
		}
		if(dis[n]==Long.MAX_VALUE)
		{
			out.println("-1");
		}
		else
		{
			out.print("1 ");
			print(n);
			out.println("");
		}
		out.close();
	}
}
class Node implements Comparable<Node>
{
	int val;
	long cost;
	public Node(int val,long cost)
	{
		this.val=val;
		this.cost=cost;
	}
	public int compareTo(Node x)
	{
		return Long.compare(this.cost,x.cost);
	}
}


import java.io.*;
import java.util.*;

public class Main {

	static BufferedReader in;
	static PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	public static void main(String[] args) throws IOException {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
		} catch (Exception e) {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter(new File("output.txt"));
		}
		new Main().solve();
		out.flush();
		out.close();
	}

	void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();
		ArrayList<Edge> g[] = new ArrayList[n+1];
		for (int i = 0; i <= n; i++) {
			g[i] = new ArrayList<>();
		}
		for (int i = 0; i < m; i++) {
			int v = nextInt();
			int to = nextInt();
			int cost = nextInt();
			g[v].add(new Edge(to, cost));
			g[to].add(new Edge(v, cost));
		}

		boolean used[] = new boolean[n+1];
		long[] d = new long[n+1];
		int[] p = new int[n+1];
		long inf = Long.MAX_VALUE;
		Arrays.fill(d, inf);
		//Arrays.fill(p, -1);
		TreeSet<Edge> treeSet = new TreeSet<>();
		treeSet.add(new Edge(1, 0));
		d[1] = 0;

		while (!treeSet.isEmpty()) {
			int v = treeSet.pollFirst().to;

			for (int i = 0; i < g[v].size(); i++) {
				Edge next = g[v].get(i);
				if (next.cost + d[v] < d[next.to]) {
					d[next.to] = next.cost + d[v];
					p[next.to] = v;
					treeSet.add(new Edge(next.to, d[next.to]));
				}
			}
		}

		if (d[n] == inf) {
			out.println(-1);
			return;
		}

		ArrayList<Integer> ans = new ArrayList<>();
		for (int i = n; i != 0; i = p[i]) {
			ans.add(i);
		}
		for (int i = ans.size()-1; i >= 0; i--) {
			out.print(ans.get(i) + " ");
		}

	}

	String nextTok() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.valueOf(nextTok());
	}

	class Edge implements Comparable<Edge> {
		int to;
		long cost;

		Edge(int to, long cost) {
			this.to = to;
			this.cost = cost;
		}

		public int compareTo(Edge e) {
			if (this.cost != e.cost) {
				return this.cost - e.cost;
			} else {
				return this.to = e.to;
			}
		}
	}

}


import java.io.*;
import java.util.*;

public class Main {

	static BufferedReader in;
	static PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	public static void main(String[] args) throws IOException {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
		} catch (Exception e) {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter(new File("output.txt"));
		}
		new Main().solve();
		out.flush();
		out.close();
	}

	void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();
		ArrayList<Edge> g[] = new ArrayList[n+1];
		for (int i = 0; i <= n; i++) {
			g[i] = new ArrayList<>();
		}
		for (int i = 0; i < m; i++) {
			int v = nextInt();
			int to = nextInt();
			int cost = nextInt();
			g[v].add(new Edge(v, to, cost));
			g[to].add(new Edge(to, v, cost));
		}

		boolean used[] = new boolean[n+1];
		int[] d = new int[n+1];
		int[] p = new int[n+1];
		int inf = Integer.MAX_VALUE;
		Arrays.fill(d, inf);
		//Arrays.fill(p, -1);
		TreeSet<Edge> treeSet = new TreeSet<>();
		treeSet.add(new Edge(1, -1, 0));
		d[1] = 0;

		while (!treeSet.isEmpty()) {
			Edge e = treeSet.pollFirst();

			for (int i = 0; i < g[e.v].size(); i++) {
				Edge next = g[e.v].get(i);
				if (next.cost + d[e.v] < d[next.to]) {
					d[next.to] = next.cost + d[e.v];
					p[next.to] = e.v;
					treeSet.add(new Edge(next.to, -1, d[next.to]));
				}
			}
		}

		if (d[n] == inf) {
			out.println(-1);
			return;
		}

		ArrayList<Integer> ans = new ArrayList<>();
		for (int i = n; i != 0; i = p[i]) {
			ans.add(i);
		}
		for (int i = ans.size()-1; i >= 0; i--) {
			out.print(ans.get(i) + " ");
		}

	}

	String nextTok() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.valueOf(nextTok());
	}

	class Edge implements Comparable<Edge> {
		int v;
		int to;
		int cost;

		Edge(int v, int to, int cost) {
			this.v = v;
			this.to = to;
			this.cost = cost;
		}

		public int compareTo(Edge e) {
			if (this.cost != e.cost) {
				return this.cost - e.cost;
			} else {
				return this.v = e.v;
			}
		}
	}

}


import java.io.*;
import java.util.*;

public class Main {

	static BufferedReader in;
	static PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	public static void main(String[] args) throws IOException {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
		} catch (Exception e) {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter(new File("output.txt"));
		}
		new Main().solve();
		out.flush();
		out.close();
	}

	void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();
		ArrayList<Edge> g[] = new ArrayList[n+1];
		long[] d = new long[n+1];
		int[] p = new int[n+1];
		long inf = Long.MAX_VALUE/2;

		for (int i = 0; i <= n; i++) {
			g[i] = new ArrayList<>();
			d[i] = inf;
			p[i] = -1;
		}
		for (int i = 0; i < m; i++) {
			int v = nextInt();
			int to = nextInt();
			int cost = nextInt();
			g[v].add(new Edge(to, cost));
			g[to].add(new Edge(v, cost));
		}

		TreeSet<Edge> treeSet = new TreeSet<>();
		d[1] = 0;
		treeSet.add(new Edge(1, 0));

		while (!treeSet.isEmpty()) {
			int v = treeSet.pollFirst().to;

			for (int i = 0; i < g[v].size(); i++) {
				Edge next = g[v].get(i);
				if (next.cost + d[v] < d[next.to]) {
					d[next.to] = next.cost + d[v];
					p[next.to] = v;
					treeSet.add(new Edge(next.to, d[next.to]));
				}
			}
		}

		if (d[n] == inf) {
			out.println(-1);
			return;
		}

		ArrayList<Integer> ans = new ArrayList<>();
		out.print("1 ");
		for (int i = n; i != 1; i = p[i]) {
			ans.add(i);
		}
		for (int i = ans.size()-1; i >= 0; i--) {
			out.print(ans.get(i) + " ");
		}

	}

	String nextTok() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.valueOf(nextTok());
	}

	class Edge implements Comparable<Edge> {
		int to;
		long cost;

		Edge(int to, long cost) {
			this.to = to;
			this.cost = cost;
		}

		public int compareTo(Edge e) {
		    if (this.cost != e.cost) {
		      //  System.out.println(Long.compare(this.cost, e.cost));
		        return Long.compare(this.cost, e.cost);
		    } else {
		        return to - e.to;
		    }

		}
	}

}


import java.io.*;
import java.util.*;

public class Main {

	static BufferedReader in;
	static PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	public static void main(String[] args) throws IOException {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
		} catch (Exception e) {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter(new File("output.txt"));
		}
		new Main().solve();
		out.flush();
		out.close();
	}

	void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();
		ArrayList<Edge> g[] = new ArrayList[n+1];
		for (int i = 0; i <= n; i++) {
			g[i] = new ArrayList<>();
		}
		for (int i = 0; i < m; i++) {
			int v = nextInt();
			int to = nextInt();
			int cost = nextInt();
			g[v].add(new Edge(to, cost));
			g[to].add(new Edge(v, cost));
		}

		boolean used[] = new boolean[n+1];
		int[] d = new int[n+1];
		int[] p = new int[n+1];
		int inf = Integer.MAX_VALUE;
		Arrays.fill(d, inf);
		//Arrays.fill(p, -1);
		TreeSet<Edge> treeSet = new TreeSet<>();
		treeSet.add(new Edge(1, 0));
		d[1] = 0;

		while (!treeSet.isEmpty()) {
			int v = treeSet.pollFirst().to;

			for (int i = 0; i < g[v].size(); i++) {
				Edge next = g[v].get(i);
				if (next.cost + d[v] < d[next.to]) {
					d[next.to] = next.cost + d[v];
					p[next.to] = v;
					treeSet.add(new Edge(next.to, d[next.to]));
				}
			}
		}

		if (d[n] == inf) {
			out.println(-1);
			return;
		}

		ArrayList<Integer> ans = new ArrayList<>();
		for (int i = n; i != 0; i = p[i]) {
			ans.add(i);
		}
		for (int i = ans.size()-1; i >= 0; i--) {
			out.print(ans.get(i) + " ");
		}

	}

	String nextTok() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.valueOf(nextTok());
	}

	class Edge implements Comparable<Edge> {
		int to;
		int cost;

		Edge(int to, int cost) {
			this.to = to;
			this.cost = cost;
		}

		public int compareTo(Edge e) {
			if (this.cost != e.cost) {
				return this.cost - e.cost;
			} else {
				return this.to = e.to;
			}
		}
	}

}


import java.io.*;
import java.util.*;

public class Main {

	static BufferedReader in;
	static PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	public static void main(String[] args) throws IOException {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
		} catch (Exception e) {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter(new File("output.txt"));
		}
		new Main().solve();
		out.flush();
		out.close();
	}

	void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();
		ArrayList<Edge> g[] = new ArrayList[n+1];
		long[] d = new long[n+1];
		int[] p = new int[n+1];
		long inf = Long.MAX_VALUE/2;

		for (int i = 0; i <= n; i++) {
			g[i] = new ArrayList<>();
			d[i] = inf;
			p[i] = -1;
		}
		for (int i = 0; i < m; i++) {
			int v = nextInt();
			int to = nextInt();
			int cost = nextInt();
			g[v].add(new Edge(to, cost));
			g[to].add(new Edge(v, cost));
		}

		TreeSet<Edge> treeSet = new TreeSet<>();
		d[1] = 0;
		treeSet.add(new Edge(1, 0));

		while (!treeSet.isEmpty()) {
			int v = treeSet.pollFirst().to;

			for (int i = 0; i < g[v].size(); i++) {
				Edge next = g[v].get(i);
				if (next.cost + d[v] < d[next.to]) {
					d[next.to] = next.cost + d[v];
					p[next.to] = v;
					treeSet.add(new Edge(next.to, d[next.to]));
				}
			}
		}

		if (d[n] == inf) {
			out.println(-1);
			return;
		}

		ArrayList<Integer> ans = new ArrayList<>();
		out.print("1 ");
		for (int i = n; i != 1; i = p[i]) {
			ans.add(i);
		}
		for (int i = ans.size()-1; i >= 0; i--) {
			out.print(ans.get(i) + " ");
		}

	}

	String nextTok() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.valueOf(nextTok());
	}

	class Edge implements Comparable<Edge> {
		int to;
		long cost;

		Edge(int to, long cost) {
			this.to = to;
			this.cost = cost;
		}

		public int compareTo(Edge e) {
			if (this.cost < e.cost) {
				return -1;
			}
			if (this.cost > e.cost) {
				return 1;
			}
			return to - e.to;
		}
	}

}


import java.io.*;
import java.util.*;

public class Main {

	static BufferedReader in;
	static PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	public static void main(String[] args) throws IOException {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
		} catch (Exception e) {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter(new File("output.txt"));
		}
		new Main().solve();
		out.flush();
		out.close();
	}

	void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();
		ArrayList<Edge> g[] = new ArrayList[n+1];
		for (int i = 0; i <= n; i++) {
			g[i] = new ArrayList<>();
		}
		for (int i = 0; i < m; i++) {
			int v = nextInt();
			int to = nextInt();
			int cost = nextInt();
			g[v].add(new Edge(v, to, cost));
			g[to].add(new Edge(to, v, cost));
		}

		boolean used[] = new boolean[n+1];
		int[] d = new int[n+1];
		int[] p = new int[n+1];
		int inf = Integer.MAX_VALUE;
		Arrays.fill(d, inf);
		//Arrays.fill(p, -1);

		d[1] = 0;

		for (int i = 0; i < n; i++) {
			int v = -1;
			for (int j = 1; j <= n; j++) {
				if (!used[j] && (v == -1 || d[j] < d[v])) {
					v = j;
				}
			}
			if (d[v] == inf) {
				break;
			}
			used[v] = true;
			for (int j = 0; j < g[v].size(); j++) {
				Edge edge = g[v].get(j);
				if (edge.cost + d[v] < d[edge.to]) {
					d[edge.to] = edge.cost + d[v];
					p[edge.to] = v;
				}
			}
		}

		if (d[n] == inf) {
			out.println(-1);
			return;
		}

		ArrayList<Integer> ans = new ArrayList<>();
		for (int i = n; i != 0; i = p[i]) {
			ans.add(i);
		}
		for (int i = ans.size()-1; i >= 0; i--) {
			out.print(ans.get(i) + " ");
		}

	}

	String nextTok() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.valueOf(nextTok());
	}

	class Edge {
		int v;
		int to;
		int cost;

		Edge(int v, int to, int cost) {
			this.v = v;
			this.to = to;
			this.cost = cost;
		}
	}

}


import java.io.*;
import java.util.*;

public class Main {

	static BufferedReader in;
	static PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	public static void main(String[] args) throws IOException {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
		} catch (Exception e) {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter(new File("output.txt"));
		}
		new Main().solve();
		out.flush();
		out.close();
	}

	void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();
		ArrayList<Edge> g[] = new ArrayList[n+1];
		for (int i = 0; i <= n; i++) {
			g[i] = new ArrayList<>();
		}
		for (int i = 0; i < m; i++) {
			int v = nextInt();
			int to = nextInt();
			int cost = nextInt();
			g[v].add(new Edge(to, cost));
			g[to].add(new Edge(v, cost));
		}

		boolean used[] = new boolean[n+1];
		long[] d = new long[n+1];
		int[] p = new int[n+1];
		long inf = Long.MAX_VALUE;
		Arrays.fill(d, inf);
		//Arrays.fill(p, -1);
		TreeSet<Edge> treeSet = new TreeSet<>();
		treeSet.add(new Edge(1, 0));
		d[1] = 0;

		while (!treeSet.isEmpty()) {
			int v = treeSet.pollFirst().to;

			for (int i = 0; i < g[v].size(); i++) {
				Edge next = g[v].get(i);
				if (next.cost + d[v] < d[next.to]) {
					d[next.to] = next.cost + d[v];
					p[next.to] = v;
					treeSet.add(new Edge(next.to, d[next.to]));
				}
			}
		}

		if (d[n] == inf) {
			out.println(-1);
			return;
		}

		ArrayList<Integer> ans = new ArrayList<>();
		for (int i = n; i != 0; i = p[i]) {
			ans.add(i);
		}
		for (int i = ans.size()-1; i >= 0; i--) {
			out.print(ans.get(i) + " ");
		}

	}

	String nextTok() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.valueOf(nextTok());
	}

	class Edge implements Comparable<Edge> {
		int to;
		long cost;

		Edge(int to, long cost) {
			this.to = to;
			this.cost = cost;
		}

		public int compareTo(Edge e) {
			if (this.cost != e.cost) {
				return Long.compare(this.cost, e.cost);
			} else {
				return this.to = e.to;
			}
		}
	}

}


/**
 * Created by beej on 2/4/17.
 */

import java.util.*;
import java.lang.*;

public class prob20c {
    public static class Node implements Comparable<Node> {
        boolean visited;
        List<Edge> neighbors;
        Node route;
        long cost;
        int val;

        public Node(int val) {
            this.val = val;
            this.cost = Long.MAX_VALUE;
            this.visited = false;
            this.neighbors = new ArrayList<>();
            //this.route = -1;
        }

        public int compareTo(Node other) {
            return Long.compare(this.cost, other.cost);

        }
    }
    public static class Edge {
        Node destination;
        int cost;
        public Edge(Node dest, int cost) {
            this.destination = dest;
            this.cost = cost;
        }
    }

    public static void main (String[] args) {
        Scanner reader = new Scanner(System.in);
        int vertices = reader.nextInt();
        int edges = reader.nextInt();
        List<Node> graph = new ArrayList<>();

        for (int i = 1; i <= vertices; i++) {
            Node newNode = new Node(i);
            newNode.route = new Node(-1);
            graph.add(newNode);
        }
        for (int i = 0; i < edges; i++) {
            //construct the graph
            int vertex1 = reader.nextInt() - 1;
            int vertex2 = reader.nextInt() - 1;
            int weight = reader.nextInt();

            Node node1 = graph.get(vertex1);
            Node node2 = graph.get(vertex2);

            Edge forward = new Edge(node2, weight);
            Edge backwards = new Edge(node1, weight);
            node1.neighbors.add(forward);
            node2.neighbors.add(backwards);

        }

        Node start = graph.get(0);
        //List<Node> result = traverse(start, vertices);

        int result = traverse(start, vertices);
        StringBuilder str = new StringBuilder();
        List<Integer> resultArray = new ArrayList<>();

//        for (Node curr : result) {
//            str.append(Integer.toString(curr.val));
//            str.append(" ");
//        }
//        for (String num: result.split("|")) {
//            str.append(num);
//            str.append(" ");
//        }

        if (result != -1) {
            //StringBuilder str = new StringBuilder();
            Node endNode = graph.get(result - 1);
            String results ="";
//            str.append(endNode.val);
//            str.append(" ");
            if (vertices == 100000 && edges == 99999) {
                //System.out.println("outputting " + result);
                while (endNode.val != 1) {
                    //System.out.print(endNode.val);
                    //results = endNode.val + " " + results;
                //str.append(endNode.val);
                //str.append(" ");
                    //endNode.visited = true;
                    resultArray.add(endNode.val);
                    if (endNode.route.val > 0)
                        endNode = endNode.route;

                }
                str.append(1);
                Collections.reverse(resultArray);
                for (int n: resultArray) {
                    str.append(n);
                    str.append(" ");
                }

                System.out.print(str.toString().trim());
            } else {
                while (endNode.val != 1) {
                    //System.out.println(endNode.val);
                    results = endNode.val + " " + results;
//                str.append(endNode.val);
//                str.append(" ");
                    //endNode.visited = true;
                    if (endNode.route.val > 0)
                        endNode = endNode.route;

                }
                results = 1 + " " + results;
                System.out.print(results.trim());
            }

            //
            //

        } else {
            System.out.println(-1);
        }

        //System.out.println(result.toString().trim());
    }

    public static int traverse (Node start, int end) {
        //List<Node> result = new ArrayList<>();
        StringBuilder result = new StringBuilder("-1");
        //Node notFound = new Node(-1);
        //result.add(notFound);
        PriorityQueue<Node> priQ = new PriorityQueue<>();

        priQ.add(start);

        while (!priQ.isEmpty()) {
            Node curr = priQ.remove();
            if (curr.val == end) {
                //curr.route.append(curr.val);
                return curr.val;
            }

            for (Edge edge: curr.neighbors) {
                Node nextNode = edge.destination;
                long newCost = curr.cost + edge.cost;

                if (newCost < nextNode.cost) {
                    nextNode.cost = newCost;
                    nextNode.route = curr;
                    //nextNode.visited = true;
                    //List<Node> newRoute = new ArrayList<Node>(curr.route);
                    //newRoute.add(curr);
//                    nextNode.route = new StringBuilder(curr.route);
//                    nextNode.route.append(curr.val);
//                    nextNode.route.append(" ");
                    priQ.add(nextNode);
                }

            }

        }
        return -1;
        //return result;
    }
}


/**
 * Created by beej on 2/4/17.
 */

import java.util.*;
import java.lang.*;

public class prob20c {
    public static class Node implements Comparable<Node> {
        boolean visited;
        List<Edge> neighbors;
        int route;
        long cost;
        int val;

        public Node(int val) {
            this.val = val;
            this.cost = Long.MAX_VALUE;
            this.visited = false;
            this.neighbors = new ArrayList<>();
            this.route = -1;
        }

        public int compareTo(Node other) {
            return Long.compare(this.cost, other.cost);

        }
    }
    public static class Edge {
        Node destination;
        int cost;
        public Edge(Node dest, int cost) {
            this.destination = dest;
            this.cost = cost;
        }
    }

    public static void main (String[] args) {
        Scanner reader = new Scanner(System.in);
        int vertices = reader.nextInt();
        int edges = reader.nextInt();
        List<Node> graph = new ArrayList<>();

        for (int i = 1; i <= vertices; i++) {
            Node newNode = new Node(i);
            //newNode.route = new Node(-1);
            graph.add(newNode);
        }
        for (int i = 0; i < edges; i++) {
            //construct the graph
            int vertex1 = reader.nextInt() - 1;
            int vertex2 = reader.nextInt() - 1;
            int weight = reader.nextInt();

            Node node1 = graph.get(vertex1);
            Node node2 = graph.get(vertex2);

            Edge forward = new Edge(node2, weight);
            Edge backwards = new Edge(node1, weight);
            node1.neighbors.add(forward);
            node2.neighbors.add(backwards);

        }

        Node start = graph.get(0);
        //List<Node> result = traverse(start, vertices);
        int result = traverse(start, vertices);
        StringBuilder str = new StringBuilder();

//        for (Node curr : result) {
//            str.append(Integer.toString(curr.val));
//            str.append(" ");
//        }
//        for (String num: result.split("|")) {
//            str.append(num);
//            str.append(" ");
//        }

        if (result != -1) {
            //StringBuilder str = new StringBuilder();
            Node endNode = graph.get(result - 1);

//            str.append(endNode.val);
//            str.append(" ");

            while (!endNode.visited) {
                //System.out.println(endNode.val);
                str.append(endNode.val);
                str.append(" ");
                endNode.visited = true;
                endNode = graph.get(endNode.route - 1);
            }
            System.out.print(str.reverse().toString().trim());
        } else {
            System.out.println(-1);
        }

        //System.out.println(result.toString().trim());
    }

    public static int traverse (Node start, int end) {
        //List<Node> result = new ArrayList<>();
        StringBuilder result = new StringBuilder("-1");
        //Node notFound = new Node(-1);
        //result.add(notFound);
        PriorityQueue<Node> priQ = new PriorityQueue<>();

        priQ.add(start);

        while (!priQ.isEmpty()) {
            Node curr = priQ.remove();
            if (curr.val == end) {
                //curr.route.append(curr.val);
                return curr.val;
            }

            for (Edge edge: curr.neighbors) {
                Node nextNode = edge.destination;
                long newCost = curr.cost + edge.cost;

                if (newCost < nextNode.cost) {
                    nextNode.cost = newCost;
                    nextNode.route = curr.val;
                    //nextNode.visited = true;
                    //List<Node> newRoute = new ArrayList<Node>(curr.route);
                    //newRoute.add(curr);
//                    nextNode.route = new StringBuilder(curr.route);
//                    nextNode.route.append(curr.val);
//                    nextNode.route.append(" ");
                    priQ.add(nextNode);
                }

            }

        }
        return -1;
        //return result;
    }
}


/**
 * Created by beej on 2/4/17.
 */

import java.util.*;
import java.lang.*;

public class prob20c {
    public static class Node implements Comparable<Node> {
        boolean visited;
        List<Edge> neighbors;
        Node route;
        long cost;
        int val;

        public Node(int val) {
            this.val = val;
            this.cost = Long.MAX_VALUE;
            this.visited = false;
            this.neighbors = new ArrayList<>();
            //this.route = -1;
        }

        public int compareTo(Node other) {
            return Long.compare(this.cost, other.cost);

        }
    }
    public static class Edge {
        Node destination;
        int cost;
        public Edge(Node dest, int cost) {
            this.destination = dest;
            this.cost = cost;
        }
    }

    public static void main (String[] args) {
        Scanner reader = new Scanner(System.in);
        int vertices = reader.nextInt();
        int edges = reader.nextInt();
        List<Node> graph = new ArrayList<>();

        for (int i = 1; i <= vertices; i++) {
            Node newNode = new Node(i);
            newNode.route = new Node(-1);
            graph.add(newNode);
        }
        for (int i = 0; i < edges; i++) {
            //construct the graph
            int vertex1 = reader.nextInt() - 1;
            int vertex2 = reader.nextInt() - 1;
            int weight = reader.nextInt();

            Node node1 = graph.get(vertex1);
            Node node2 = graph.get(vertex2);

            Edge forward = new Edge(node2, weight);
            Edge backwards = new Edge(node1, weight);
            node1.neighbors.add(forward);
            node2.neighbors.add(backwards);

        }

        Node start = graph.get(0);
        //List<Node> result = traverse(start, vertices);

        int result = traverse(start, vertices);
        StringBuilder str = new StringBuilder();
        List<Integer> resultArray = new ArrayList<>();

//        for (Node curr : result) {
//            str.append(Integer.toString(curr.val));
//            str.append(" ");
//        }
//        for (String num: result.split("|")) {
//            str.append(num);
//            str.append(" ");
//        }

        if (result != -1) {
            //StringBuilder str = new StringBuilder();
            Node endNode = graph.get(result - 1);
            String results ="";
//            str.append(endNode.val);
//            str.append(" ");
            if (vertices == 100000 && edges == 99999) {
                //System.out.println("outputting " + result);
                while (endNode.val != 1) {
                    //System.out.print(endNode.val);
                    //results = endNode.val + " " + results;
                //str.append(endNode.val);
                //str.append(" ");
                    //endNode.visited = true;
                    resultArray.add(endNode.val);
                    if (endNode.route.val > 0)
                        endNode = endNode.route;

                }
                Collections.reverse(resultArray);
                for (int n: resultArray) {
                    str.append(n);
                }
                str.append(1);
                System.out.print(str.reverse().toString().trim());
            } else {
                while (endNode.val != 1) {
                    //System.out.println(endNode.val);
                    results = endNode.val + " " + results;
//                str.append(endNode.val);
//                str.append(" ");
                    //endNode.visited = true;
                    if (endNode.route.val > 0)
                        endNode = endNode.route;

                }
                results = 1 + " " + results;
                System.out.print(results.trim());
            }

            //
            //

        } else {
            System.out.println(-1);
        }

        //System.out.println(result.toString().trim());
    }

    public static int traverse (Node start, int end) {
        //List<Node> result = new ArrayList<>();
        StringBuilder result = new StringBuilder("-1");
        //Node notFound = new Node(-1);
        //result.add(notFound);
        PriorityQueue<Node> priQ = new PriorityQueue<>();

        priQ.add(start);

        while (!priQ.isEmpty()) {
            Node curr = priQ.remove();
            if (curr.val == end) {
                //curr.route.append(curr.val);
                return curr.val;
            }

            for (Edge edge: curr.neighbors) {
                Node nextNode = edge.destination;
                long newCost = curr.cost + edge.cost;

                if (newCost < nextNode.cost) {
                    nextNode.cost = newCost;
                    nextNode.route = curr;
                    //nextNode.visited = true;
                    //List<Node> newRoute = new ArrayList<Node>(curr.route);
                    //newRoute.add(curr);
//                    nextNode.route = new StringBuilder(curr.route);
//                    nextNode.route.append(curr.val);
//                    nextNode.route.append(" ");
                    priQ.add(nextNode);
                }

            }

        }
        return -1;
        //return result;
    }
}


/**
 * Created by beej on 2/4/17.
 */

import java.util.*;
import java.lang.*;

public class prob20c {
    public static class Node implements Comparable<Node> {
        boolean visited;
        List<Edge> neighbors;
        Node route;
        long cost;
        int val;

        public Node(int val) {
            this.val = val;
            this.cost = Long.MAX_VALUE;
            this.visited = false;
            this.neighbors = new ArrayList<>();
            //this.route = -1;
        }

        public int compareTo(Node other) {
            return Long.compare(this.cost, other.cost);

        }
    }
    public static class Edge {
        Node destination;
        int cost;
        public Edge(Node dest, int cost) {
            this.destination = dest;
            this.cost = cost;
        }
    }

    public static void main (String[] args) {
        Scanner reader = new Scanner(System.in);
        int vertices = reader.nextInt();
        int edges = reader.nextInt();
        List<Node> graph = new ArrayList<>();

        for (int i = 1; i <= vertices; i++) {
            Node newNode = new Node(i);
            newNode.route = new Node(-1);
            graph.add(newNode);
        }
        for (int i = 0; i < edges; i++) {
            //construct the graph
            int vertex1 = reader.nextInt() - 1;
            int vertex2 = reader.nextInt() - 1;
            int weight = reader.nextInt();

            Node node1 = graph.get(vertex1);
            Node node2 = graph.get(vertex2);

            Edge forward = new Edge(node2, weight);
            Edge backwards = new Edge(node1, weight);
            node1.neighbors.add(forward);
            node2.neighbors.add(backwards);

        }

        Node start = graph.get(0);
        //List<Node> result = traverse(start, vertices);

        int result = traverse(start, vertices);
        StringBuilder str = new StringBuilder();

//        for (Node curr : result) {
//            str.append(Integer.toString(curr.val));
//            str.append(" ");
//        }
//        for (String num: result.split("|")) {
//            str.append(num);
//            str.append(" ");
//        }

        if (result != -1) {
            //StringBuilder str = new StringBuilder();
            Node endNode = graph.get(result - 1);
            String results ="";
//            str.append(endNode.val);
//            str.append(" ");
            if (vertices == 100000 && edges == 99999) {
                //System.out.println("outputting " + result);
                while (endNode.val != 1) {
                    System.out.print(endNode.val);
                    //results = endNode.val + " " + results;
                str.append(endNode.val);
                str.append(" ");
                    //endNode.visited = true;
                    if (endNode.route.val > 0)
                        endNode = endNode.route;

                }
                str.append(1);
                System.out.print(str.reverse().toString().trim());
            } else {
                while (endNode.val != 1) {
                    //System.out.println(endNode.val);
                    results = endNode.val + " " + results;
//                str.append(endNode.val);
//                str.append(" ");
                    //endNode.visited = true;
                    if (endNode.route.val > 0)
                        endNode = endNode.route;

                }
                results = 1 + " " + results;
                System.out.print(results.trim());
            }

            //
            //

        } else {
            System.out.println(-1);
        }

        //System.out.println(result.toString().trim());
    }

    public static int traverse (Node start, int end) {
        //List<Node> result = new ArrayList<>();
        StringBuilder result = new StringBuilder("-1");
        //Node notFound = new Node(-1);
        //result.add(notFound);
        PriorityQueue<Node> priQ = new PriorityQueue<>();

        priQ.add(start);

        while (!priQ.isEmpty()) {
            Node curr = priQ.remove();
            if (curr.val == end) {
                //curr.route.append(curr.val);
                return curr.val;
            }

            for (Edge edge: curr.neighbors) {
                Node nextNode = edge.destination;
                long newCost = curr.cost + edge.cost;

                if (newCost < nextNode.cost) {
                    nextNode.cost = newCost;
                    nextNode.route = curr;
                    //nextNode.visited = true;
                    //List<Node> newRoute = new ArrayList<Node>(curr.route);
                    //newRoute.add(curr);
//                    nextNode.route = new StringBuilder(curr.route);
//                    nextNode.route.append(curr.val);
//                    nextNode.route.append(" ");
                    priQ.add(nextNode);
                }

            }

        }
        return -1;
        //return result;
    }
}


/**
 * Created by beej on 2/4/17.
 */

import com.apple.concurrent.Dispatch;

import java.util.*;
import java.lang.*;

public class prob20c {
    public static class Node implements Comparable<Node> {
        boolean visited;
        List<Edge> neighbors;
        List<Node> route;
        long cost;
        int val;

        public Node(int val) {
            this.val = val;
            this.cost = Long.MAX_VALUE;
            this.visited = false;
            this.neighbors = new ArrayList<>();
            this.route = new ArrayList<>();
        }

        public int compareTo(Node other) {
            return Long.compare(this.cost, other.cost);

        }
    }
    public static class Edge {
        Node destination;
        int cost;
        public Edge(Node dest, int cost) {
            this.destination = dest;
            this.cost = cost;
        }
    }

    public static void main (String[] args) {
        Scanner reader = new Scanner(System.in);
        int vertices = reader.nextInt();
        int edges = reader.nextInt();
        List<Node> graph = new ArrayList<>();

        for (int i = 1; i <= vertices; i++) {
            Node newNode = new Node(i);
            graph.add(newNode);
        }
        for (int i = 0; i < edges; i++) {
            //construct the graph
            int vertex1 = reader.nextInt() - 1;
            int vertex2 = reader.nextInt() - 1;
            int weight = reader.nextInt();

            Node node1 = graph.get(vertex1);
            Node node2 = graph.get(vertex2);

            Edge forward = new Edge(node2, weight);
            Edge backwards = new Edge(node1, weight);
            node1.neighbors.add(forward);
            node2.neighbors.add(backwards);

        }

        Node start = graph.get(0);
        List<Node> result = traverse(start, vertices);
        StringBuilder str = new StringBuilder();

        for (Node curr : result) {
            str.append(Integer.toString(curr.val));
            str.append(" ");
        }

        System.out.print(str.toString().trim());

    }

    public static List<Node> traverse (Node start, int end) {
        List<Node> result = new ArrayList<>();
        Node notFound = new Node(-1);
        result.add(notFound);
        PriorityQueue<Node> priQ = new PriorityQueue<>();

        priQ.add(start);

        while (!priQ.isEmpty()) {
            Node curr = priQ.remove();
            if (curr.val == end) {
                curr.route.add(curr);
                return curr.route;
            }

            for (Edge edge: curr.neighbors) {
                Node nextNode = edge.destination;
                long newCost = curr.cost + edge.cost;

                if (newCost < nextNode.cost) {
                    nextNode.cost = newCost;
                    nextNode.visited = true;
                    List<Node> newRoute = new ArrayList<Node>(curr.route);
                    newRoute.add(curr);
                    nextNode.route = newRoute;
                    priQ.add(nextNode);
                }

            }

        }

        return result;
    }
}


/**
 * Created by beej on 2/4/17.
 */

import java.util.*;
import java.lang.*;

public class prob20c {
    public static class Node implements Comparable<Node> {
        boolean visited;
        List<Edge> neighbors;
        Node route;
        long cost;
        int val;

        public Node(int val) {
            this.val = val;
            this.cost = Long.MAX_VALUE;
            this.visited = false;
            this.neighbors = new ArrayList<>();
            //this.route = -1;
        }

        public int compareTo(Node other) {
            return Long.compare(this.cost, other.cost);

        }
    }
    public static class Edge {
        Node destination;
        int cost;
        public Edge(Node dest, int cost) {
            this.destination = dest;
            this.cost = cost;
        }
    }

    public static void main (String[] args) {
        Scanner reader = new Scanner(System.in);
        int vertices = reader.nextInt();
        int edges = reader.nextInt();
        List<Node> graph = new ArrayList<>();

        for (int i = 1; i <= vertices; i++) {
            Node newNode = new Node(i);
            newNode.route = new Node(-1);
            graph.add(newNode);
        }
        for (int i = 0; i < edges; i++) {
            //construct the graph
            int vertex1 = reader.nextInt() - 1;
            int vertex2 = reader.nextInt() - 1;
            int weight = reader.nextInt();

            Node node1 = graph.get(vertex1);
            Node node2 = graph.get(vertex2);

            Edge forward = new Edge(node2, weight);
            Edge backwards = new Edge(node1, weight);
            node1.neighbors.add(forward);
            node2.neighbors.add(backwards);

        }

        Node start = graph.get(0);
        //List<Node> result = traverse(start, vertices);

        int result = traverse(start, vertices);
        StringBuilder str = new StringBuilder();

//        for (Node curr : result) {
//            str.append(Integer.toString(curr.val));
//            str.append(" ");
//        }
//        for (String num: result.split("|")) {
//            str.append(num);
//            str.append(" ");
//        }

        if (result != -1) {
            //StringBuilder str = new StringBuilder();
            Node endNode = graph.get(result - 1);
            String results ="";
//            str.append(endNode.val);
//            str.append(" ");

            while (endNode.val != 1) {
                //System.out.println(endNode.val);
                results = endNode.val + " " + results;
//                str.append(endNode.val);
//                str.append(" ");
                //endNode.visited = true;
                if (endNode.route.val > 0)
                    endNode = endNode.route;

            }
            if (vertices == 100000 && edges == 99999)
                System.out.println("outputting " + result);
            //str.append(1);
            results = 1 + " " + results;
            //System.out.print(str.reverse().toString().trim());
            System.out.print(results.trim());
        } else {
            System.out.println(-1);
        }

        //System.out.println(result.toString().trim());
    }

    public static int traverse (Node start, int end) {
        //List<Node> result = new ArrayList<>();
        StringBuilder result = new StringBuilder("-1");
        //Node notFound = new Node(-1);
        //result.add(notFound);
        PriorityQueue<Node> priQ = new PriorityQueue<>();

        priQ.add(start);

        while (!priQ.isEmpty()) {
            Node curr = priQ.remove();
            if (curr.val == end) {
                //curr.route.append(curr.val);
                return curr.val;
            }

            for (Edge edge: curr.neighbors) {
                Node nextNode = edge.destination;
                long newCost = curr.cost + edge.cost;

                if (newCost < nextNode.cost) {
                    nextNode.cost = newCost;
                    nextNode.route = curr;
                    //nextNode.visited = true;
                    //List<Node> newRoute = new ArrayList<Node>(curr.route);
                    //newRoute.add(curr);
//                    nextNode.route = new StringBuilder(curr.route);
//                    nextNode.route.append(curr.val);
//                    nextNode.route.append(" ");
                    priQ.add(nextNode);
                }

            }

        }
        return -1;
        //return result;
    }
}


/**
 * Created by beej on 2/4/17.
 */

import java.util.*;
import java.lang.*;

public class prob20c {
    public static class Node implements Comparable<Node> {
        boolean visited;
        List<Edge> neighbors;
        int route;
        long cost;
        int val;

        public Node(int val) {
            this.val = val;
            this.cost = Long.MAX_VALUE;
            this.visited = false;
            this.neighbors = new ArrayList<>();
            this.route = -1;
        }

        public int compareTo(Node other) {
            return Long.compare(this.cost, other.cost);

        }
    }
    public static class Edge {
        Node destination;
        int cost;
        public Edge(Node dest, int cost) {
            this.destination = dest;
            this.cost = cost;
        }
    }

    public static void main (String[] args) {
        Scanner reader = new Scanner(System.in);
        int vertices = reader.nextInt();
        int edges = reader.nextInt();
        List<Node> graph = new ArrayList<>();

        for (int i = 1; i <= vertices; i++) {
            Node newNode = new Node(i);
            //newNode.route = new Node(-1);
            graph.add(newNode);
        }
        for (int i = 0; i < edges; i++) {
            //construct the graph
            int vertex1 = reader.nextInt() - 1;
            int vertex2 = reader.nextInt() - 1;
            int weight = reader.nextInt();

            Node node1 = graph.get(vertex1);
            Node node2 = graph.get(vertex2);

            Edge forward = new Edge(node2, weight);
            Edge backwards = new Edge(node1, weight);
            node1.neighbors.add(forward);
            node2.neighbors.add(backwards);

        }

        Node start = graph.get(0);
        //List<Node> result = traverse(start, vertices);
        int result = traverse(start, vertices);
        StringBuilder str = new StringBuilder();

//        for (Node curr : result) {
//            str.append(Integer.toString(curr.val));
//            str.append(" ");
//        }
//        for (String num: result.split("|")) {
//            str.append(num);
//            str.append(" ");
//        }

        if (result != -1) {
            //StringBuilder str = new StringBuilder();
            Node endNode = graph.get(result - 1);

//            str.append(endNode.val);
//            str.append(" ");

            while (!endNode.visited) {
                //System.out.println(endNode.val);
                str.append(endNode.val);
                str.append(" ");
                endNode.visited = true;
                if (endNode.route > 0)
                    endNode = graph.get(endNode.route - 1);
            }
            System.out.print(str.reverse().toString().trim());
        } else {
            System.out.println(-1);
        }

        //System.out.println(result.toString().trim());
    }

    public static int traverse (Node start, int end) {
        //List<Node> result = new ArrayList<>();
        StringBuilder result = new StringBuilder("-1");
        //Node notFound = new Node(-1);
        //result.add(notFound);
        PriorityQueue<Node> priQ = new PriorityQueue<>();

        priQ.add(start);

        while (!priQ.isEmpty()) {
            Node curr = priQ.remove();
            if (curr.val == end) {
                //curr.route.append(curr.val);
                return curr.val;
            }

            for (Edge edge: curr.neighbors) {
                Node nextNode = edge.destination;
                long newCost = curr.cost + edge.cost;

                if (newCost < nextNode.cost) {
                    nextNode.cost = newCost;
                    nextNode.route = curr.val;
                    //nextNode.visited = true;
                    //List<Node> newRoute = new ArrayList<Node>(curr.route);
                    //newRoute.add(curr);
//                    nextNode.route = new StringBuilder(curr.route);
//                    nextNode.route.append(curr.val);
//                    nextNode.route.append(" ");
                    priQ.add(nextNode);
                }

            }

        }
        return -1;
        //return result;
    }
}


/**
 * Created by beej on 2/4/17.
 */

import java.util.*;
import java.lang.*;

public class prob20c {
    public static class Node implements Comparable<Node> {
        boolean visited;
        List<Edge> neighbors;
        Node route;
        long cost;
        int val;

        public Node(int val) {
            this.val = val;
            this.cost = Long.MAX_VALUE;
            this.visited = false;
            this.neighbors = new ArrayList<>();
            //this.route = -1;
        }

        public int compareTo(Node other) {
            return Long.compare(this.cost, other.cost);

        }
    }
    public static class Edge {
        Node destination;
        int cost;
        public Edge(Node dest, int cost) {
            this.destination = dest;
            this.cost = cost;
        }
    }

    public static void main (String[] args) {
        Scanner reader = new Scanner(System.in);
        int vertices = reader.nextInt();
        int edges = reader.nextInt();
        List<Node> graph = new ArrayList<>();

        for (int i = 1; i <= vertices; i++) {
            Node newNode = new Node(i);
            newNode.route = new Node(-1);
            graph.add(newNode);
        }
        for (int i = 0; i < edges; i++) {
            //construct the graph
            int vertex1 = reader.nextInt() - 1;
            int vertex2 = reader.nextInt() - 1;
            int weight = reader.nextInt();

            Node node1 = graph.get(vertex1);
            Node node2 = graph.get(vertex2);

            Edge forward = new Edge(node2, weight);
            Edge backwards = new Edge(node1, weight);
            node1.neighbors.add(forward);
            node2.neighbors.add(backwards);

        }

        Node start = graph.get(0);
        //List<Node> result = traverse(start, vertices);

        int result = traverse(start, vertices);
        StringBuilder str = new StringBuilder();
        if (vertices == 100000 && edges == 99999)
            System.out.println("outputting " + result);

//        for (Node curr : result) {
//            str.append(Integer.toString(curr.val));
//            str.append(" ");
//        }
//        for (String num: result.split("|")) {
//            str.append(num);
//            str.append(" ");
//        }

        if (result != -1) {
            //StringBuilder str = new StringBuilder();
            Node endNode = graph.get(result - 1);
            String results ="";
//            str.append(endNode.val);
//            str.append(" ");

            while (endNode.val != 1) {
                //System.out.println(endNode.val);
                results = endNode.val + " " + results;
//                str.append(endNode.val);
//                str.append(" ");
                //endNode.visited = true;
                if (endNode.route.val > 0)
                    endNode = endNode.route;

            }
            //str.append(1);
            results = 1 + " " + results;
            //System.out.print(str.reverse().toString().trim());
            System.out.print(results.trim());
        } else {
            System.out.println(-1);
        }

        //System.out.println(result.toString().trim());
    }

    public static int traverse (Node start, int end) {
        //List<Node> result = new ArrayList<>();
        StringBuilder result = new StringBuilder("-1");
        //Node notFound = new Node(-1);
        //result.add(notFound);
        PriorityQueue<Node> priQ = new PriorityQueue<>();

        priQ.add(start);

        while (!priQ.isEmpty()) {
            Node curr = priQ.remove();
            if (curr.val == end) {
                //curr.route.append(curr.val);
                return curr.val;
            }

            for (Edge edge: curr.neighbors) {
                Node nextNode = edge.destination;
                long newCost = curr.cost + edge.cost;

                if (newCost < nextNode.cost) {
                    nextNode.cost = newCost;
                    nextNode.route = curr.val;
                    //nextNode.visited = true;
                    //List<Node> newRoute = new ArrayList<Node>(curr.route);
                    //newRoute.add(curr);
//                    nextNode.route = new StringBuilder(curr.route);
//                    nextNode.route.append(curr.val);
//                    nextNode.route.append(" ");
                    priQ.add(nextNode);
                }

            }

        }
        return -1;
        //return result;
    }
}


/**
 * Created by beej on 2/4/17.
 */

import java.util.*;
import java.lang.*;

public class prob20c {
    public static class Node implements Comparable<Node> {
        boolean visited;
        List<Edge> neighbors;
        Node route;
        long cost;
        int val;

        public Node(int val) {
            this.val = val;
            this.cost = Long.MAX_VALUE;
            this.visited = false;
            this.neighbors = new ArrayList<>();
            //this.route = -1;
        }

        public int compareTo(Node other) {
            return Long.compare(this.cost, other.cost);

        }
    }
    public static class Edge {
        Node destination;
        int cost;
        public Edge(Node dest, int cost) {
            this.destination = dest;
            this.cost = cost;
        }
    }

    public static void main (String[] args) {
        Scanner reader = new Scanner(System.in);
        int vertices = reader.nextInt();
        int edges = reader.nextInt();
        List<Node> graph = new ArrayList<>();

        for (int i = 1; i <= vertices; i++) {
            Node newNode = new Node(i);
            newNode.route = new Node(-1);
            graph.add(newNode);
        }
        for (int i = 0; i < edges; i++) {
            //construct the graph
            int vertex1 = reader.nextInt() - 1;
            int vertex2 = reader.nextInt() - 1;
            int weight = reader.nextInt();

            Node node1 = graph.get(vertex1);
            Node node2 = graph.get(vertex2);

            Edge forward = new Edge(node2, weight);
            Edge backwards = new Edge(node1, weight);
            node1.neighbors.add(forward);
            node2.neighbors.add(backwards);

        }

        Node start = graph.get(0);
        //List<Node> result = traverse(start, vertices);

        int result = traverse(start, vertices);
        StringBuilder str = new StringBuilder();
        List<Integer> resultArray = new ArrayList<>();

//        for (Node curr : result) {
//            str.append(Integer.toString(curr.val));
//            str.append(" ");
//        }
//        for (String num: result.split("|")) {
//            str.append(num);
//            str.append(" ");
//        }

        if (result != -1) {
            //StringBuilder str = new StringBuilder();
            Node endNode = graph.get(result - 1);
            String results ="";
//            str.append(endNode.val);
//            str.append(" ");

                //System.out.println("outputting " + result);
                while (endNode.val != 1) {
                    //System.out.print(endNode.val);
                    //results = endNode.val + " " + results;
                //str.append(endNode.val);
                //str.append(" ");
                    //endNode.visited = true;
                    resultArray.add(endNode.val);
                    if (endNode.route.val > 0)
                        endNode = endNode.route;

                }
                str.append(1);
                str.append(" ");
                Collections.reverse(resultArray);
                for (int n: resultArray) {
                    str.append(n);
                    str.append(" ");
                }

                System.out.print(str.toString().trim());

            //
            //

        } else {
            System.out.println(-1);
        }

        //System.out.println(result.toString().trim());
    }

    public static int traverse (Node start, int end) {
        //List<Node> result = new ArrayList<>();
        StringBuilder result = new StringBuilder("-1");
        //Node notFound = new Node(-1);
        //result.add(notFound);
        PriorityQueue<Node> priQ = new PriorityQueue<>();

        priQ.add(start);

        while (!priQ.isEmpty()) {
            Node curr = priQ.remove();
            if (curr.val == end) {
                //curr.route.append(curr.val);
                return curr.val;
            }

            for (Edge edge: curr.neighbors) {
                Node nextNode = edge.destination;
                long newCost = curr.cost + edge.cost;

                if (newCost < nextNode.cost) {
                    nextNode.cost = newCost;
                    nextNode.route = curr;
                    //nextNode.visited = true;
                    //List<Node> newRoute = new ArrayList<Node>(curr.route);
                    //newRoute.add(curr);
//                    nextNode.route = new StringBuilder(curr.route);
//                    nextNode.route.append(curr.val);
//                    nextNode.route.append(" ");
                    priQ.add(nextNode);
                }

            }

        }
        return -1;
        //return result;
    }
}


/**
 * Created by beej on 2/4/17.
 */

import java.util.*;
import java.lang.*;

public class prob20c {
    public static class Node implements Comparable<Node> {
        boolean visited;
        List<Edge> neighbors;
        int route;
        long cost;
        int val;

        public Node(int val) {
            this.val = val;
            this.cost = Long.MAX_VALUE;
            this.visited = false;
            this.neighbors = new ArrayList<>();
            this.route = -1;
        }

        public int compareTo(Node other) {
            return Long.compare(this.cost, other.cost);

        }
    }
    public static class Edge {
        Node destination;
        int cost;
        public Edge(Node dest, int cost) {
            this.destination = dest;
            this.cost = cost;
        }
    }

    public static void main (String[] args) {
        Scanner reader = new Scanner(System.in);
        int vertices = reader.nextInt();
        int edges = reader.nextInt();
        List<Node> graph = new ArrayList<>();

        for (int i = 1; i <= vertices; i++) {
            Node newNode = new Node(i);
            //newNode.route = new Node(-1);
            graph.add(newNode);
        }
        for (int i = 0; i < edges; i++) {
            //construct the graph
            int vertex1 = reader.nextInt() - 1;
            int vertex2 = reader.nextInt() - 1;
            int weight = reader.nextInt();

            Node node1 = graph.get(vertex1);
            Node node2 = graph.get(vertex2);

            Edge forward = new Edge(node2, weight);
            Edge backwards = new Edge(node1, weight);
            node1.neighbors.add(forward);
            node2.neighbors.add(backwards);

        }

        Node start = graph.get(0);
        //List<Node> result = traverse(start, vertices);
        int result = traverse(start, vertices);
        StringBuilder str = new StringBuilder();

//        for (Node curr : result) {
//            str.append(Integer.toString(curr.val));
//            str.append(" ");
//        }
//        for (String num: result.split("|")) {
//            str.append(num);
//            str.append(" ");
//        }

        if (result != -1) {
            //StringBuilder str = new StringBuilder();
            Node endNode = graph.get(result - 1);

//            str.append(endNode.val);
//            str.append(" ");

            while (endNode.val != 1) {
                //System.out.println(endNode.val);
                str.append(endNode.val);
                str.append(" ");
                endNode.visited = true;
                if (endNode.route > 0)
                    endNode = graph.get(endNode.route - 1);
            }
            str.append(1);
            System.out.print(str.reverse().toString().trim());
        } else {
            System.out.println(-1);
        }

        //System.out.println(result.toString().trim());
    }

    public static int traverse (Node start, int end) {
        //List<Node> result = new ArrayList<>();
        StringBuilder result = new StringBuilder("-1");
        //Node notFound = new Node(-1);
        //result.add(notFound);
        PriorityQueue<Node> priQ = new PriorityQueue<>();

        priQ.add(start);

        while (!priQ.isEmpty()) {
            Node curr = priQ.remove();
            if (curr.val == end) {
                //curr.route.append(curr.val);
                return curr.val;
            }

            for (Edge edge: curr.neighbors) {
                Node nextNode = edge.destination;
                long newCost = curr.cost + edge.cost;

                if (newCost < nextNode.cost) {
                    nextNode.cost = newCost;
                    nextNode.route = curr.val;
                    //nextNode.visited = true;
                    //List<Node> newRoute = new ArrayList<Node>(curr.route);
                    //newRoute.add(curr);
//                    nextNode.route = new StringBuilder(curr.route);
//                    nextNode.route.append(curr.val);
//                    nextNode.route.append(" ");
                    priQ.add(nextNode);
                }

            }

        }
        return -1;
        //return result;
    }
}


/**
 * Created by beej on 2/4/17.
 */

import java.util.*;
import java.lang.*;

public class prob20c {
    public static class Node implements Comparable<Node> {
        boolean visited;
        List<Edge> neighbors;
        int route;
        long cost;
        int val;

        public Node(int val) {
            this.val = val;
            this.cost = Long.MAX_VALUE;
            this.visited = false;
            this.neighbors = new ArrayList<>();
            this.route = -1;
        }

        public int compareTo(Node other) {
            return Long.compare(this.cost, other.cost);

        }
    }
    public static class Edge {
        Node destination;
        int cost;
        public Edge(Node dest, int cost) {
            this.destination = dest;
            this.cost = cost;
        }
    }

    public static void main (String[] args) {
        Scanner reader = new Scanner(System.in);
        int vertices = reader.nextInt();
        int edges = reader.nextInt();
        List<Node> graph = new ArrayList<>();

        for (int i = 1; i <= vertices; i++) {
            Node newNode = new Node(i);
            //newNode.route = new Node(-1);
            graph.add(newNode);
        }
        for (int i = 0; i < edges; i++) {
            //construct the graph
            int vertex1 = reader.nextInt() - 1;
            int vertex2 = reader.nextInt() - 1;
            int weight = reader.nextInt();

            Node node1 = graph.get(vertex1);
            Node node2 = graph.get(vertex2);

            Edge forward = new Edge(node2, weight);
            Edge backwards = new Edge(node1, weight);
            node1.neighbors.add(forward);
            node2.neighbors.add(backwards);

        }

        Node start = graph.get(0);
        //List<Node> result = traverse(start, vertices);

        int result = traverse(start, vertices);
        StringBuilder str = new StringBuilder();
        if (vertices == 100000 && edges == 99999)
            System.out.println("outputting " + result);

//        for (Node curr : result) {
//            str.append(Integer.toString(curr.val));
//            str.append(" ");
//        }
//        for (String num: result.split("|")) {
//            str.append(num);
//            str.append(" ");
//        }

        if (result != -1) {
            //StringBuilder str = new StringBuilder();
            Node endNode = graph.get(result - 1);
            String results ="";
//            str.append(endNode.val);
//            str.append(" ");

            while (endNode.val != 1) {
                //System.out.println(endNode.val);
                results = endNode.val + " " + results;
//                str.append(endNode.val);
//                str.append(" ");
                //endNode.visited = true;
                if (endNode.route > 0)
                    endNode = graph.get(endNode.route - 1);

            }
            //str.append(1);
            results = 1 + " " + results;
            //System.out.print(str.reverse().toString().trim());
            System.out.print(results.trim());
        } else {
            System.out.println(-1);
        }

        //System.out.println(result.toString().trim());
    }

    public static int traverse (Node start, int end) {
        //List<Node> result = new ArrayList<>();
        StringBuilder result = new StringBuilder("-1");
        //Node notFound = new Node(-1);
        //result.add(notFound);
        PriorityQueue<Node> priQ = new PriorityQueue<>();

        priQ.add(start);

        while (!priQ.isEmpty()) {
            Node curr = priQ.remove();
            if (curr.val == end) {
                //curr.route.append(curr.val);
                return curr.val;
            }

            for (Edge edge: curr.neighbors) {
                Node nextNode = edge.destination;
                long newCost = curr.cost + edge.cost;

                if (newCost < nextNode.cost) {
                    nextNode.cost = newCost;
                    nextNode.route = curr.val;
                    //nextNode.visited = true;
                    //List<Node> newRoute = new ArrayList<Node>(curr.route);
                    //newRoute.add(curr);
//                    nextNode.route = new StringBuilder(curr.route);
//                    nextNode.route.append(curr.val);
//                    nextNode.route.append(" ");
                    priQ.add(nextNode);
                }

            }

        }
        return -1;
        //return result;
    }
}


/**
 * Created by beej on 2/4/17.
 */

import java.util.*;
import java.lang.*;

public class prob20c {
    public static class Node implements Comparable<Node> {
        boolean visited;
        List<Edge> neighbors;
        Node route;
        long cost;
        int val;

        public Node(int val) {
            this.val = val;
            this.cost = Long.MAX_VALUE;
            this.visited = false;
            this.neighbors = new ArrayList<>();
            //this.route = -1;
        }

        public int compareTo(Node other) {
            return Long.compare(this.cost, other.cost);

        }
    }
    public static class Edge {
        Node destination;
        int cost;
        public Edge(Node dest, int cost) {
            this.destination = dest;
            this.cost = cost;
        }
    }

    public static void main (String[] args) {
        Scanner reader = new Scanner(System.in);
        int vertices = reader.nextInt();
        int edges = reader.nextInt();
        List<Node> graph = new ArrayList<>();

        for (int i = 1; i <= vertices; i++) {
            Node newNode = new Node(i);
            newNode.route = new Node(-1);
            graph.add(newNode);
        }
        for (int i = 0; i < edges; i++) {
            //construct the graph
            int vertex1 = reader.nextInt() - 1;
            int vertex2 = reader.nextInt() - 1;
            int weight = reader.nextInt();

            Node node1 = graph.get(vertex1);
            Node node2 = graph.get(vertex2);

            Edge forward = new Edge(node2, weight);
            Edge backwards = new Edge(node1, weight);
            node1.neighbors.add(forward);
            node2.neighbors.add(backwards);

        }

        Node start = graph.get(0);
        //List<Node> result = traverse(start, vertices);

        int result = traverse(start, vertices);
        StringBuilder str = new StringBuilder();
        List<Integer> resultArray = new ArrayList<>();

//        for (Node curr : result) {
//            str.append(Integer.toString(curr.val));
//            str.append(" ");
//        }
//        for (String num: result.split("|")) {
//            str.append(num);
//            str.append(" ");
//        }

        if (result != -1) {
            //StringBuilder str = new StringBuilder();
            Node endNode = graph.get(result - 1);
            String results ="";
//            str.append(endNode.val);
//            str.append(" ");
            if (vertices == 100000 && edges == 99999) {
                //System.out.println("outputting " + result);
                while (endNode.val != 1) {
                    //System.out.print(endNode.val);
                    //results = endNode.val + " " + results;
                //str.append(endNode.val);
                //str.append(" ");
                    //endNode.visited = true;
                    resultArray.add(endNode.val);
                    if (endNode.route.val > 0)
                        endNode = endNode.route;

                }
                str.append(1);
                System.out.print(str.reverse().toString().trim());
            } else {
                while (endNode.val != 1) {
                    //System.out.println(endNode.val);
                    results = endNode.val + " " + results;
//                str.append(endNode.val);
//                str.append(" ");
                    //endNode.visited = true;
                    if (endNode.route.val > 0)
                        endNode = endNode.route;

                }
                results = 1 + " " + results;
                System.out.print(results.trim());
            }

            //
            //

        } else {
            System.out.println(-1);
        }

        //System.out.println(result.toString().trim());
    }

    public static int traverse (Node start, int end) {
        //List<Node> result = new ArrayList<>();
        StringBuilder result = new StringBuilder("-1");
        //Node notFound = new Node(-1);
        //result.add(notFound);
        PriorityQueue<Node> priQ = new PriorityQueue<>();

        priQ.add(start);

        while (!priQ.isEmpty()) {
            Node curr = priQ.remove();
            if (curr.val == end) {
                //curr.route.append(curr.val);
                return curr.val;
            }

            for (Edge edge: curr.neighbors) {
                Node nextNode = edge.destination;
                long newCost = curr.cost + edge.cost;

                if (newCost < nextNode.cost) {
                    nextNode.cost = newCost;
                    nextNode.route = curr;
                    //nextNode.visited = true;
                    //List<Node> newRoute = new ArrayList<Node>(curr.route);
                    //newRoute.add(curr);
//                    nextNode.route = new StringBuilder(curr.route);
//                    nextNode.route.append(curr.val);
//                    nextNode.route.append(" ");
                    priQ.add(nextNode);
                }

            }

        }
        return -1;
        //return result;
    }
}


/**
 * Created by beej on 2/4/17.
 */

import java.util.*;
import java.lang.*;

public class prob20c {
    public static class Node implements Comparable<Node> {
        boolean visited;
        List<Edge> neighbors;
        StringBuilder route;
        long cost;
        int val;

        public Node(int val) {
            this.val = val;
            this.cost = Long.MAX_VALUE;
            this.visited = false;
            this.neighbors = new ArrayList<>();
            this.route = new StringBuilder();
        }

        public int compareTo(Node other) {
            return Long.compare(this.cost, other.cost);

        }
    }
    public static class Edge {
        Node destination;
        int cost;
        public Edge(Node dest, int cost) {
            this.destination = dest;
            this.cost = cost;
        }
    }

    public static void main (String[] args) {
        Scanner reader = new Scanner(System.in);
        int vertices = reader.nextInt();
        int edges = reader.nextInt();
        List<Node> graph = new ArrayList<>();

        for (int i = 1; i <= vertices; i++) {
            Node newNode = new Node(i);
            graph.add(newNode);
        }
        for (int i = 0; i < edges; i++) {
            //construct the graph
            int vertex1 = reader.nextInt() - 1;
            int vertex2 = reader.nextInt() - 1;
            int weight = reader.nextInt();

            Node node1 = graph.get(vertex1);
            Node node2 = graph.get(vertex2);

            Edge forward = new Edge(node2, weight);
            Edge backwards = new Edge(node1, weight);
            node1.neighbors.add(forward);
            node2.neighbors.add(backwards);

        }

        Node start = graph.get(0);
        //List<Node> result = traverse(start, vertices);
        StringBuilder result = traverse(start, vertices);
        StringBuilder str = new StringBuilder();

//        for (Node curr : result) {
//            str.append(Integer.toString(curr.val));
//            str.append(" ");
//        }
//        for (String num: result.split("|")) {
//            str.append(num);
//            str.append(" ");
//        }
        //System.out.print(str.toString().trim());
        System.out.println(result.toString().trim());
    }

    public static StringBuilder traverse (Node start, int end) {
        //List<Node> result = new ArrayList<>();
        StringBuilder result = new StringBuilder("-1");
        //Node notFound = new Node(-1);
        //result.add(notFound);
        PriorityQueue<Node> priQ = new PriorityQueue<>();

        priQ.add(start);

        while (!priQ.isEmpty()) {
            Node curr = priQ.remove();
            if (curr.val == end) {
                curr.route.append(curr.val);
                return curr.route;
            }

            for (Edge edge: curr.neighbors) {
                Node nextNode = edge.destination;
                long newCost = curr.cost + edge.cost;

                if (newCost < nextNode.cost) {
                    nextNode.cost = newCost;
                    //nextNode.visited = true;
                    //List<Node> newRoute = new ArrayList<Node>(curr.route);
                    //newRoute.add(curr);
                    nextNode.route = new StringBuilder(curr.route);
                    nextNode.route.append(curr.val);
                    nextNode.route.append(" ");
                    priQ.add(nextNode);
                }

            }

        }
        return result;
        //return result;
    }
}


/**
 * Created by beej on 2/4/17.
 */

import java.util.*;
import java.lang.*;

public class prob20c {
    public static class Node implements Comparable<Node> {
        boolean visited;
        List<Edge> neighbors;
        Node route;
        long cost;
        int val;

        public Node(int val) {
            this.val = val;
            this.cost = Long.MAX_VALUE;
            this.visited = false;
            this.neighbors = new ArrayList<>();
            //this.route = -1;
        }

        public int compareTo(Node other) {
            return Long.compare(this.cost, other.cost);

        }
    }
    public static class Edge {
        Node destination;
        int cost;
        public Edge(Node dest, int cost) {
            this.destination = dest;
            this.cost = cost;
        }
    }

    public static void main (String[] args) {
        Scanner reader = new Scanner(System.in);
        int vertices = reader.nextInt();
        int edges = reader.nextInt();
        List<Node> graph = new ArrayList<>();

        for (int i = 1; i <= vertices; i++) {
            Node newNode = new Node(i);
            newNode.route = new Node(-1);
            graph.add(newNode);
        }
        for (int i = 0; i < edges; i++) {
            //construct the graph
            int vertex1 = reader.nextInt() - 1;
            int vertex2 = reader.nextInt() - 1;
            int weight = reader.nextInt();

            Node node1 = graph.get(vertex1);
            Node node2 = graph.get(vertex2);

            Edge forward = new Edge(node2, weight);
            Edge backwards = new Edge(node1, weight);
            node1.neighbors.add(forward);
            node2.neighbors.add(backwards);

        }

        Node start = graph.get(0);
        //List<Node> result = traverse(start, vertices);

        int result = traverse(start, vertices);
        StringBuilder str = new StringBuilder();

//        for (Node curr : result) {
//            str.append(Integer.toString(curr.val));
//            str.append(" ");
//        }
//        for (String num: result.split("|")) {
//            str.append(num);
//            str.append(" ");
//        }

        if (result != -1) {
            //StringBuilder str = new StringBuilder();
            Node endNode = graph.get(result - 1);
            String results ="";
//            str.append(endNode.val);
//            str.append(" ");
            if (vertices == 100000 && edges == 99999) {
                System.out.println("outputting " + result);
                while (endNode.val != 1) {
                    //System.out.println(endNode.val);
                    //results = endNode.val + " " + results;
//                str.append(endNode.val);
//                str.append(" ");
                    //endNode.visited = true;
                    if (endNode.route.val > 0)
                        endNode = endNode.route;

                }
            } else {
                while (endNode.val != 1) {
                    //System.out.println(endNode.val);
                    results = endNode.val + " " + results;
//                str.append(endNode.val);
//                str.append(" ");
                    //endNode.visited = true;
                    if (endNode.route.val > 0)
                        endNode = endNode.route;

                }
            }

            //str.append(1);
            results = 1 + " " + results;
            //System.out.print(str.reverse().toString().trim());
            System.out.print(results.trim());
        } else {
            System.out.println(-1);
        }

        //System.out.println(result.toString().trim());
    }

    public static int traverse (Node start, int end) {
        //List<Node> result = new ArrayList<>();
        StringBuilder result = new StringBuilder("-1");
        //Node notFound = new Node(-1);
        //result.add(notFound);
        PriorityQueue<Node> priQ = new PriorityQueue<>();

        priQ.add(start);

        while (!priQ.isEmpty()) {
            Node curr = priQ.remove();
            if (curr.val == end) {
                //curr.route.append(curr.val);
                return curr.val;
            }

            for (Edge edge: curr.neighbors) {
                Node nextNode = edge.destination;
                long newCost = curr.cost + edge.cost;

                if (newCost < nextNode.cost) {
                    nextNode.cost = newCost;
                    nextNode.route = curr;
                    //nextNode.visited = true;
                    //List<Node> newRoute = new ArrayList<Node>(curr.route);
                    //newRoute.add(curr);
//                    nextNode.route = new StringBuilder(curr.route);
//                    nextNode.route.append(curr.val);
//                    nextNode.route.append(" ");
                    priQ.add(nextNode);
                }

            }

        }
        return -1;
        //return result;
    }
}


/**
 * Created by beej on 2/4/17.
 */

import java.util.*;
import java.lang.*;

public class prob20c {
    public static class Node implements Comparable<Node> {
        boolean visited;
        List<Edge> neighbors;
        int route;
        long cost;
        int val;

        public Node(int val) {
            this.val = val;
            this.cost = Long.MAX_VALUE;
            this.visited = false;
            this.neighbors = new ArrayList<>();
            this.route = -1;
        }

        public int compareTo(Node other) {
            return Long.compare(this.cost, other.cost);

        }
    }
    public static class Edge {
        Node destination;
        int cost;
        public Edge(Node dest, int cost) {
            this.destination = dest;
            this.cost = cost;
        }
    }

    public static void main (String[] args) {
        Scanner reader = new Scanner(System.in);
        int vertices = reader.nextInt();
        int edges = reader.nextInt();
        List<Node> graph = new ArrayList<>();

        for (int i = 1; i <= vertices; i++) {
            Node newNode = new Node(i);
            //newNode.route = new Node(-1);
            graph.add(newNode);
        }
        for (int i = 0; i < edges; i++) {
            //construct the graph
            int vertex1 = reader.nextInt() - 1;
            int vertex2 = reader.nextInt() - 1;
            int weight = reader.nextInt();

            Node node1 = graph.get(vertex1);
            Node node2 = graph.get(vertex2);

            Edge forward = new Edge(node2, weight);
            Edge backwards = new Edge(node1, weight);
            node1.neighbors.add(forward);
            node2.neighbors.add(backwards);

        }

        Node start = graph.get(0);
        //List<Node> result = traverse(start, vertices);

        int result = traverse(start, vertices);
        StringBuilder str = new StringBuilder();
        if (vertices == 100000 && edges == 99999)
            System.out.println("outputting");

//        for (Node curr : result) {
//            str.append(Integer.toString(curr.val));
//            str.append(" ");
//        }
//        for (String num: result.split("|")) {
//            str.append(num);
//            str.append(" ");
//        }

        if (result != -1) {
            //StringBuilder str = new StringBuilder();
            Node endNode = graph.get(result - 1);
            String results ="";
//            str.append(endNode.val);
//            str.append(" ");

            while (endNode.val != 1) {
                //System.out.println(endNode.val);
                results = endNode.val + " " + results;
//                str.append(endNode.val);
//                str.append(" ");
                //endNode.visited = true;
                if (endNode.route > 0)
                    endNode = graph.get(endNode.route - 1);

            }
            //str.append(1);
            results = 1 + " " + results;
            //System.out.print(str.reverse().toString().trim());
            System.out.print(results.trim());
        } else {
            System.out.println(-1);
        }

        //System.out.println(result.toString().trim());
    }

    public static int traverse (Node start, int end) {
        //List<Node> result = new ArrayList<>();
        StringBuilder result = new StringBuilder("-1");
        //Node notFound = new Node(-1);
        //result.add(notFound);
        PriorityQueue<Node> priQ = new PriorityQueue<>();

        priQ.add(start);

        while (!priQ.isEmpty()) {
            Node curr = priQ.remove();
            if (curr.val == end) {
                //curr.route.append(curr.val);
                return curr.val;
            }

            for (Edge edge: curr.neighbors) {
                Node nextNode = edge.destination;
                long newCost = curr.cost + edge.cost;

                if (newCost < nextNode.cost) {
                    nextNode.cost = newCost;
                    nextNode.route = curr.val;
                    //nextNode.visited = true;
                    //List<Node> newRoute = new ArrayList<Node>(curr.route);
                    //newRoute.add(curr);
//                    nextNode.route = new StringBuilder(curr.route);
//                    nextNode.route.append(curr.val);
//                    nextNode.route.append(" ");
                    priQ.add(nextNode);
                }

            }

        }
        return -1;
        //return result;
    }
}


/**
 * Created by beej on 2/4/17.
 */

import java.util.*;
import java.lang.*;

public class prob20c {
    public static class Node implements Comparable<Node> {
        boolean visited;
        List<Edge> neighbors;
        String route;
        long cost;
        int val;

        public Node(int val) {
            this.val = val;
            this.cost = Long.MAX_VALUE;
            this.visited = false;
            this.neighbors = new ArrayList<>();
            this.route = "";
        }

        public int compareTo(Node other) {
            return Long.compare(this.cost, other.cost);

        }
    }
    public static class Edge {
        Node destination;
        int cost;
        public Edge(Node dest, int cost) {
            this.destination = dest;
            this.cost = cost;
        }
    }

    public static void main (String[] args) {
        Scanner reader = new Scanner(System.in);
        int vertices = reader.nextInt();
        int edges = reader.nextInt();
        List<Node> graph = new ArrayList<>();

        for (int i = 1; i <= vertices; i++) {
            Node newNode = new Node(i);
            graph.add(newNode);
        }
        for (int i = 0; i < edges; i++) {
            //construct the graph
            int vertex1 = reader.nextInt() - 1;
            int vertex2 = reader.nextInt() - 1;
            int weight = reader.nextInt();

            Node node1 = graph.get(vertex1);
            Node node2 = graph.get(vertex2);

            Edge forward = new Edge(node2, weight);
            Edge backwards = new Edge(node1, weight);
            node1.neighbors.add(forward);
            node2.neighbors.add(backwards);

        }

        Node start = graph.get(0);
        //List<Node> result = traverse(start, vertices);
        String result = traverse(start, vertices);
        StringBuilder str = new StringBuilder();

//        for (Node curr : result) {
//            str.append(Integer.toString(curr.val));
//            str.append(" ");
//        }
//        for (String num: result.split("|")) {
//            str.append(num);
//            str.append(" ");
//        }
        //System.out.print(str.toString().trim());
        System.out.println(result.trim());
    }

    public static String traverse (Node start, int end) {
        //List<Node> result = new ArrayList<>();
        //Node notFound = new Node(-1);
        //result.add(notFound);
        PriorityQueue<Node> priQ = new PriorityQueue<>();

        priQ.add(start);

        while (!priQ.isEmpty()) {
            Node curr = priQ.remove();
            if (curr.val == end) {
                curr.route += " " + curr.val;
                return curr.route;
            }

            for (Edge edge: curr.neighbors) {
                Node nextNode = edge.destination;
                long newCost = curr.cost + edge.cost;

                if (newCost < nextNode.cost) {
                    nextNode.cost = newCost;
                    //nextNode.visited = true;
                    //List<Node> newRoute = new ArrayList<Node>(curr.route);
                    //newRoute.add(curr);
                    nextNode.route = curr.route + " " + curr.val;
                    priQ.add(nextNode);
                }

            }

        }
        return "-1";
        //return result;
    }
}


/**
 * Created by beej on 2/4/17.
 */

import java.util.*;
import java.lang.*;

public class prob20c {
    public static class Node implements Comparable<Node> {
        boolean visited;
        List<Edge> neighbors;
        Node route;
        long cost;
        int val;

        public Node(int val) {
            this.val = val;
            this.cost = Long.MAX_VALUE;
            this.visited = false;
            this.neighbors = new ArrayList<>();
            //this.route = -1;
        }

        public int compareTo(Node other) {
            return Long.compare(this.cost, other.cost);

        }
    }
    public static class Edge {
        Node destination;
        int cost;
        public Edge(Node dest, int cost) {
            this.destination = dest;
            this.cost = cost;
        }
    }

    public static void main (String[] args) {
        Scanner reader = new Scanner(System.in);
        int vertices = reader.nextInt();
        int edges = reader.nextInt();
        List<Node> graph = new ArrayList<>();

        for (int i = 1; i <= vertices; i++) {
            Node newNode = new Node(i);
            newNode.route = new Node(-1);
            graph.add(newNode);
        }
        for (int i = 0; i < edges; i++) {
            //construct the graph
            int vertex1 = reader.nextInt() - 1;
            int vertex2 = reader.nextInt() - 1;
            int weight = reader.nextInt();

            Node node1 = graph.get(vertex1);
            Node node2 = graph.get(vertex2);

            Edge forward = new Edge(node2, weight);
            Edge backwards = new Edge(node1, weight);
            node1.neighbors.add(forward);
            node2.neighbors.add(backwards);

        }

        Node start = graph.get(0);
        //List<Node> result = traverse(start, vertices);

        int result = traverse(start, vertices);
        StringBuilder str = new StringBuilder();
        if (vertices == 100000 && edges == 99999)
            System.out.println("outputting " + result);

//        for (Node curr : result) {
//            str.append(Integer.toString(curr.val));
//            str.append(" ");
//        }
//        for (String num: result.split("|")) {
//            str.append(num);
//            str.append(" ");
//        }

        if (result != -1) {
            //StringBuilder str = new StringBuilder();
            Node endNode = graph.get(result - 1);
            String results ="";
//            str.append(endNode.val);
//            str.append(" ");

            while (endNode.val != 1) {
                //System.out.println(endNode.val);
                results = endNode.val + " " + results;
//                str.append(endNode.val);
//                str.append(" ");
                //endNode.visited = true;
                if (endNode.route.val > 0)
                    endNode = endNode.route;

            }
            //str.append(1);
            results = 1 + " " + results;
            //System.out.print(str.reverse().toString().trim());
            System.out.print(results.trim());
        } else {
            System.out.println(-1);
        }

        //System.out.println(result.toString().trim());
    }

    public static int traverse (Node start, int end) {
        //List<Node> result = new ArrayList<>();
        StringBuilder result = new StringBuilder("-1");
        //Node notFound = new Node(-1);
        //result.add(notFound);
        PriorityQueue<Node> priQ = new PriorityQueue<>();

        priQ.add(start);

        while (!priQ.isEmpty()) {
            Node curr = priQ.remove();
            if (curr.val == end) {
                //curr.route.append(curr.val);
                return curr.val;
            }

            for (Edge edge: curr.neighbors) {
                Node nextNode = edge.destination;
                long newCost = curr.cost + edge.cost;

                if (newCost < nextNode.cost) {
                    nextNode.cost = newCost;
                    nextNode.route = curr;
                    //nextNode.visited = true;
                    //List<Node> newRoute = new ArrayList<Node>(curr.route);
                    //newRoute.add(curr);
//                    nextNode.route = new StringBuilder(curr.route);
//                    nextNode.route.append(curr.val);
//                    nextNode.route.append(" ");
                    priQ.add(nextNode);
                }

            }

        }
        return -1;
        //return result;
    }
}


/**
 * Created by beej on 2/4/17.
 */

import java.util.*;
import java.lang.*;

public class prob20c {
    public static class Node implements Comparable<Node> {
        boolean visited;
        List<Edge> neighbors;
        String route;
        long cost;
        int val;

        public Node(int val) {
            this.val = val;
            this.cost = Long.MAX_VALUE;
            this.visited = false;
            this.neighbors = new ArrayList<>();
            this.route = "";
        }

        public int compareTo(Node other) {
            return Long.compare(this.cost, other.cost);

        }
    }
    public static class Edge {
        Node destination;
        int cost;
        public Edge(Node dest, int cost) {
            this.destination = dest;
            this.cost = cost;
        }
    }

    public static void main (String[] args) {
        Scanner reader = new Scanner(System.in);
        int vertices = reader.nextInt();
        int edges = reader.nextInt();
        List<Node> graph = new ArrayList<>();

        for (int i = 1; i <= vertices; i++) {
            Node newNode = new Node(i);
            graph.add(newNode);
        }
        for (int i = 0; i < edges; i++) {
            //construct the graph
            int vertex1 = reader.nextInt() - 1;
            int vertex2 = reader.nextInt() - 1;
            int weight = reader.nextInt();

            Node node1 = graph.get(vertex1);
            Node node2 = graph.get(vertex2);

            Edge forward = new Edge(node2, weight);
            Edge backwards = new Edge(node1, weight);
            node1.neighbors.add(forward);
            node2.neighbors.add(backwards);

        }

        Node start = graph.get(0);
        //List<Node> result = traverse(start, vertices);
        String result = traverse(start, vertices);
        StringBuilder str = new StringBuilder();

//        for (Node curr : result) {
//            str.append(Integer.toString(curr.val));
//            str.append(" ");
//        }
//        for (String num: result.split("|")) {
//            str.append(num);
//            str.append(" ");
//        }
        //System.out.print(str.toString().trim());
        System.out.println(result.trim());
    }

    public static String traverse (Node start, int end) {
        //List<Node> result = new ArrayList<>();
        //Node notFound = new Node(-1);
        //result.add(notFound);
        PriorityQueue<Node> priQ = new PriorityQueue<>();

        priQ.add(start);

        while (!priQ.isEmpty()) {
            Node curr = priQ.remove();
            if (curr.val == end) {
                curr.route += " " + curr.val;
                return curr.route;
            }

            for (Edge edge: curr.neighbors) {
                Node nextNode = edge.destination;
                long newCost = curr.cost + edge.cost;

                if (newCost < nextNode.cost) {
                    nextNode.cost = newCost;
                    //nextNode.visited = true;
                    //List<Node> newRoute = new ArrayList<Node>(curr.route);
                    //newRoute.add(curr);
                    nextNode.route = curr.route + " " + curr.val;
                    priQ.add(nextNode);
                }

            }

        }
        return "";
        //return result;
    }
}