from collections import deque
import sys
input = sys.stdin.readline
n,m,k,x = map(int,input().split())
result = [-1]*(n+1)
result[x] = 0 #시작점
path = [[] for _ in range(n+1)]
for _ in range(m):
a,b = map(int,input().split())
path[a].append(b) #간선 연결
queue = deque([x])
while queue:
now = queue.popleft()
for nextcity in path[now]:
if result[nextcity] == False :
result[nextcity] = result[now]+1
queue.append(nextcity)
for i in range(n+1):
if result[i]==k:
print(i)
#없으면
if k not in result:
print(-1)
-1로 초기화하고 갈때마다 1씩 증가시켜준다