import queue n,m,a,b=map(int,input().split()) a-=1 g=[[] for i in range(n+1)] for i in range(m): l,r=map(int,input().split()) l-=1 if lb:l=b if r>b:r=b g[l].append(r) g[r].append(l) que=queue.Queue() que.put((a,0)) dist=[-1]*(n+1) while(not que.empty()): p=que.get() if dist[p[0]]!=-1:continue dist[p[0]]=p[1] for to in g[p[0]]: que.put((to,p[1]+1)) print(dist[b])