import sys input = sys.stdin.readline from collections import deque inf = 10 ** 18 def bfs(G, s, N): Q = deque([]) dist = [inf] * N par = [inf] * N for i in range(s): dist[i] = 0 Q.append(i) while Q: u = Q.popleft() for v in G[u]: if dist[v] != inf: continue dist[v] = dist[u] + 1 par[v] = u Q.append(v) return dist N, M, A, B = map(int, input().split()) G = [[] for i in range(N + 1)] for i in range(M): L, R = map(int, input().split()) L -= 1 G[L].append(R) G[R].append(L) D = bfs(G, A, N + 1) ans = min(D[B:]) print(ans) if ans != inf else print(-1)