from collections import deque N,M,A,B=map(int,input().split()) G=[[] for _ in range(N+1)] for _ in range(M): l,r=map(int,input().split()) G[l-1].append(r) G[r].append(l-1) D=deque() depth=[-1]*(N+1) for i in range(A): D.append(i) depth[i]=0 while D: v=D.popleft() for nv in G[v]: if depth[nv]==-1: depth[nv]=depth[v]+1 D.append(nv) ans=10**9 for i in range(B,N+1): if depth[i]!=-1: ans=min(ans,depth[i]) if ans==10**9: print(-1) else: print(ans)