#include using namespace std; #include using namespace atcoder; // #include // using namespace boost::multiprecision; #define ll long long #define ld long double #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define vi vector #define vl vector #define vd vector #define vb vector #define vs vector #define vc vector #define ull unsigned long long #define chmax(a, b) a = max(a, (b)) #define chmin(a, b) a = min(a, (b)) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() // #define ll int // #define ll int128_t // #define ll int256_t // #define ll cpp_int constexpr ll inf = (1ll << 60); // constexpr ll inf = (1 << 30); // const double PI=3.1415926535897932384626433832795028841971; // ll rui(ll a,ll b){ // if(b==0)return 1; // if(b%2==1) return a*rui(a*a,b/2); // return rui(a*a,b/2); // } // vl fact; // ll kai(ll n){ // fact.resize(n,1); // rep(i,n-1)fact[i+1]=fact[i]*(i+1); // } using mint = modint998244353;//static_modint<998244353> // using mint = modint1000000007;//static_modint<1000000007> // using mint = static_modint<922267487>; // 多分落とされにくい NOT ntt-friendly // using mint = static_modint<469762049>; // ntt-friendly // using mint = static_modint<167772161>; // ntt-friendly // using mint = modint;//mint::set_mod(mod); // ll const mod=1000000007ll; // ll const mod=998244353ll; // ll modrui(ll a,ll b,ll mod){ // a%=mod; // if(b[i]==0)return 1; // if(b%2==1) return a*modrui(a*a%mod,b/2,mod)%mod; // return modrui(a*a%mod,b/2,mod)%mod; // } // ll inv(ll x){ // x%=mod; // return modrui(x,mod-2); // } // void incr(vl &v,ll n){// n進法 // ll k=v.size(); // v[k-1]++; // ll now=k-1; // while (v[now]>=n) // { // v[now]=0; // if(now==0)break; // v[now-1]++; // now--; // } // return; // } // vector fact,invf; // void init_modfact(ll sz){ // fact.resize(sz); // invf.resize(sz); // fact[0]=1; // rep(i,sz-1){ // fact[i+1]=fact[i]*(i+1); // } // invf[sz-1]=1/fact[sz-1]; // for(ll i=sz-2; i>=0; i--){ // invf[i]=invf[i+1]*(i+1); // } // } // mint choose(ll n,ll r){ // if(n modpow,invpow; // void init_modpow(ll x,ll sz){ // mint inv=1/mint(x); // modpow.assign(sz,1); // invpow.assign(sz,1); // rep(i,sz-1){ // modpow[i+1]=modpow[i]*x; // invpow[i+1]=invpow[i]*inv; // } // } ll off=10000000; void solve(){ ll v,e,s,g; cin >> v >> e >> s >> g; s--; g--; vl a(e),b(e); vector>> h(v); rep(i,e){ cin >> a[i] >> b[i]; a[i]--; b[i]--; h[a[i]].insert({b[i],off}); h[b[i]].insert({a[i],off}); } { vector> es(v); rep(i,e){ es[a[i]].insert(b[i]); es[b[i]].insert(a[i]); } vl deg(v,0); rep(i,v){ deg[i]=es[i].size(); } deque dq(0); rep(i,v){ if(deg[i]==1)dq.push_back(i); } while(!dq.empty()){ ll x=dq[0]; dq.pop_front(); assert(es[x].size()<=1); if(es[x].size()==0)continue; ll y=*es[x].begin(); es[x].erase(y); es[y].erase(x); deg[x]--; deg[y]--; if(deg[y]==1){ dq.push_back(y); } } rep(i,v){ for(auto &p:es[i]){ h[i].erase({p,off}); h[i].insert({p,off-1}); } } } ll n=v; vl dist(n,inf); vc decided(n,0); priority_queue,vector>,greater>> pq; dist[s]=0; pq.push({0,s}); while(!pq.empty()){ auto [d,x]=pq.top(); pq.pop(); if(decided[x])continue; decided[x]=1; for(auto &edge:h[x]){ ll to=edge.first,cost=edge.second; if(!decided[to] && dist[to]>d+cost){ dist[to]=d+cost; pq.push({d+cost,to}); } } } if(dist[g]==inf)cout << -1 << endl; else{ cout << ((off-dist[g])%off+off)%off << endl; } } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); ll t = 1; // cin >> t; while (t--) solve(); }