#include using namespace std; using ll = long long; int main(){ int n,m,a,b; cin>>n>>m>>a>>b; vector> g(n+2); a--;b--; for(int i = 0;i>l>>r; l--; g[l].push_back(r); g[r].push_back(l); } int ans = 1e9; vector vis(n+2,1e9); for(int i = 0;i que; que.push_back(i); vector use; vis[i] = 0; while(que.size()){ int ni = que.front(); que.pop_front(); use.push_back(ni); for(auto&to:g[ni]){ if(vis[to]<=vis[ni]) continue; vis[to] = vis[ni]+1; que.push_back(to); } } for(auto&j:use) vis[j] = 1e9; for(auto&j:use){ if(j<=a) { que.push_back(j); vis[j] = 1; } } while(que.size()){ int ni = que.front(); que.pop_front(); for(auto&to:g[ni]){ if(vis[to]<=vis[ni]) continue; vis[to] = vis[ni] + 1; que.push_back(to); } } for(auto&j:use){ if(j==n+1) continue; if(j<=b) continue; ans = min(ans,vis[j]-1); } for(auto&j:use) vis[j] = 0; } if(ans>=1e8) cout<<-1<