#include using namespace std; #define ALL(a) (a).begin(),(a).end() #define ALLR(a) (a).rbegin(),(a).rend() #define rep(i,n,m) for(int i = (n); i < (int)(m); i++) #define rrep(i,n,m) for(int i = (m) - 1; i >= (int)(n); i--) using ll = long long; using ld = long double; const ll MOD = 1e9+7; //const ll MOD = 998244353; const ll INF = 1e9+1; template bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;} template bool chmax(T &a,T b){if(a vectordx={1,0,-1,0,1,1,-1,-1}; vectordy={0,1,0,-1,1,-1,1,-1}; template vector make_v(size_t a,T b){return vector(a,b);} template auto make_v(size_t a,Ts... ts){ return vector(a,make_v(ts...)); } ll MAX_V = 2e5 + 5; struct edge { ll to,cost; edge(ll x,ll y):to(x),cost(y){}; }; //<最短距離, 頂点の番号> using P = pair; vector dist(MAX_V); //各頂点への最短距離 void dijkstra(ll s,vector>&g) { priority_queue, greater

> que; fill(dist.begin(),dist.begin()+g.size(), INF); dist[s] = 0; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); ll v = p.second; if (dist[v] < p.first) continue; for (ll i=0; i dist[v] + e.cost) { dist[e.to] = dist[v] + e.cost; que.push(P(dist[e.to], e.to)); } } } } int main(){ int n,m,a,b;cin>>n>>m>>a>>b; a--;b--; vector>g(n+1); rep(i,0,m){ int l,r; cin>>l>>r; l--; chmax(l,a); chmin(l,b+1); chmax(r,a); chmin(r,b+1); g[l].emplace_back(r,1); g[r].emplace_back(l,1); } dijkstra(a,g); if(dist[b+1]!=INF)cout<