n,m,a,b=map(int,input().split()) lr=[list(map(int,input().split())) for _ in range(m)] g=[[] for _ in range(n+2)] for l,r in lr: r+=1 g[l].append(r) g[r].append(l) from heapq import heappush,heappop inf=float('inf') seen=[inf]*(n+2) ans=inf for i in range(a): g[0].append(i+1) todo=[[0,0]] seen[0]=0 while todo: c,v=heappop(todo) if v>b: ans=min(ans,c) continue if seen[v]!=c:continue for nv in g[v]: nc=c if nv>a:nc+=1 if seen[nv]>nc: seen[nv]=nc heappush(todo,[nc,nv]) print(-1 if ans==inf else ans)