# Code: Get Path - BFS
# Send Feedback
# Given an undirected graph G(V, E) and two vertices v1 and v2(as integers), find and print the path from v1 to v2(if exists). Print nothing if there is no path between v1 and v2.
# Find the path using BFS and print the shortest path available.
# Note:
# 1. V is the number of vertices present in graph G and vertices are numbered from 0 to V-1.
# 2. E is the number of edges present in graph G.
# 3. Print the path in reverse order. That is, print v2 first, then intermediate vertices and v1 at last.
# 4. Save the input graph in Adjacency Matrix.
# Input Format:
# The first line of input contains two integers, that denote the value of V and E.
# Each of the following E lines contains two integers, that denote that there exists an edge between vertex a and b.
# The following line contain two integers, that denote the value of v1 and v2.
# Output Format:
# Print the path from v1 to v2 in reverse order.
# Constraints:
# 2 <= V <= 1000
# 1 <= E <= (V * (V - 1)) / 2
# 0 <= a <= V - 1
# 0 <= b <= V - 1
# 0 <= v1 <= 2 ^ 31 - 1
# 0 <= v2 <= 2 ^ 31 - 1
# Time Limit: 1 second
# Sample Input 1:
# 4 4
# 0 1
# 0 3
# 1 2
# 2 3
# 1 3
# Sample Output 1:
# 3 0 1
# Sample Input 2:
# 6 3
# 5 3
# 0 1
# 3 4
# 0 3
# Sample Output 2:
import queue
from sys import stdin, setrecursionlimit
setrecursionlimit(10**6)


class Graph:
    def __init__(self, nVertices):
        self.nVertices = nVertices
        self.adjMatrix = [[0 for i in range(nVertices)]
                          for j in range(nVertices)]

    def addEdge(self, v1, v2):
        self.adjMatrix[v1][v2] = 1
        self.adjMatrix[v2][v1] = 1

    def removeEdge(self):
        if self.containsEdge(v1, v2) is False:
            return
        self.adjMatrix[v1][v2] = 0
        self.adjMatrix[v2][v1] = 0

    def containsEdge(self, v1, v2):
        if self.adjMatrix[v1][v2] > 0:
            return True
        else:
            return False

    def __str__(self):
        return str(self.adjMatrix)

    def __getPathBFS(self, sv, ev, visited):
        mapp = {}
        q = queue.Queue()

        if self.adjMatrix[sv][ev] == 1 and sv == ev:
            ans = []
            ans.append(sv)
            return ans

        q.put(sv)
        visited[sv] = True

        while q.empty() is False:
            front = q.get()

            for i in range(self.nVertices):
                if self.adjMatrix[front][i] == 1 and visited[i] is False:
                    mapp[i] = front
                    q.put(i)

                    visited[i] = True

                    if i == ev:
                        ans = []
                        ans.append(ev)
                        value = mapp[ev]

                        while value != sv:
                            ans.append(value)
                            value = mapp[value]

                        ans.append(value)
                        return ans

        return []

    def getPathBFS(self, sv, ev):

        # Return empty list in case sv or ev is invalid
        if (sv > (self.nVertices - 1)) or (ev > (self.nVertices - 1)):
            return list()
        visited = [False for i in range(self.nVertices)]
        return self.__getPathBFS(sv, ev, visited)


# Main
li = stdin.readline().strip().split()
V = int(li[0])
E = int(li[1])

g = Graph(V)

for i in range(E):
    arr = stdin.readline().strip().split()
    fv = int(arr[0])
    sv = int(arr[1])
    g.addEdge(fv, sv)

li = stdin.readline().strip().split()
sv = int(li[0])
ev = int(li[1])

li = g.getPathBFS(sv, ev)

if len(li) != 0:
	for element in li:
		print(element, end=' ')
