#include using namespace std; using ll = long long; using pii = pair; using pll = pair; using vi = vector; using vl = vector; #define ov4(a, b, c, d, name, ...) name #define rep3(i, a, b, c) for(ll i = (a); i < (b); i += (c)) #define rep2(i, a, b) rep3(i, a, b, 1) #define rep1(i, n) rep2(i, 0, n) #define rep0(n) rep1(aaaaa, n) #define rep(...) ov4(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__) #define per(i, a, b) for(ll i = (a)-1; i >= (b); i--) #define fore(e, v) for(auto&& e : v) #define all(a) begin(a), end(a) #define si(a) (int)(size(a)) #define lb(v, x) (lower_bound(all(v), x) - begin(v)) #define eb emplace_back template bool chmin(T& a, const S& b) { return a > b ? a = b, 1 : 0; } template bool chmax(T& a, const S& b) { return a < b ? a = b, 1 : 0; } const int INF = 1e9 + 100; const ll INFL = 3e18 + 100; #define i128 __int128_t template struct LL { int n; const G g; vi ord, low, arti; vector bridge; LL(G g) : n(si(g)), g(g), ord(si(g), -1), low(si(g), -1) { int k = 0; rep(i, n) { if(ord[i] == -1) k = dfs(i, k, -1); } } int dfs(int x, int k, int p) { low[x] = (ord[x] = k++); int cnt = 0; bool is_arti = false, second = false; fore(e, g[x]) { if(ord[e] == -1) { cnt++; k = dfs(e, k, x); chmin(low[x], low[e]); is_arti |= (p != -1) && (low[e] >= ord[x]); if(ord[x] < low[e]) bridge.eb(minmax(x, e)); } else if(e != p or second) { chmin(low[x], ord[e]); } else { second = true; } } is_arti |= p == -1 && cnt > 1; if(is_arti) arti.eb(x); return k; } }; int main() { cin.tie(0)->sync_with_stdio(0); ll n,m,s,g; cin >> n >> m >> s >> g; s--; g--; vector> edge(n); rep(i,m){ ll u,v; cin >> u >> v; u--; v--; edge[u].push_back(v); edge[v].push_back(u); } LL>> lowlink(edge); set se; for(auto [u,v]:lowlink.bridge){ se.emplace(u,v); se.emplace(v,u); } vl dist(n,1LL<<60); dist[s] = 0; priority_queue, greater> q; q.emplace(0,s); while(!q.empty()){ auto [v,now] = q.top(); q.pop(); if(v > dist[now]){continue;} ll x = dist[now] / n; ll y = dist[now] % n; for(auto to:edge[now]){ ll cost = 0; if(se.count(make_pair(now,to)) == 1){ cost = 1; } if(chmin(dist[to], (x + 1) * n + (y + cost))){ q.emplace(dist[to],to); } } } ll ans; if(dist[g] == (1LL<<60)){ ans = -1; } else{ ans = dist[g] / n - dist[g] % n; } cerr << dist[g] << endl; cout << ans << endl; }