# https://yukicoder.me/problems/no/3463 from collections import deque import heapq MAX_INT = 10 ** 18 def main(): V, E, S, G = map(int, input().split()) ab = [] for _ in range(E): a, b = map(int ,input().split()) ab.append((a - 1 ,b - 1)) # 次数1のグラフから徐々に削っていって残ったものだけ next_nodes = [{} for _ in range(V)] for i in range(E): a, b = ab[i] next_nodes[a][b] = i next_nodes[b][a] = i queue = deque() for i in range(V): if len(next_nodes[i]) == 1: queue.append(i) not_cycle = set() while len(queue) > 0: v = queue.popleft() for w, edge_inex in next_nodes[v].items(): del next_nodes[w][v] not_cycle.add(edge_inex) if len(next_nodes[w]) == 1: queue.append(w) next_nodes[v].clear() # ダイクストラ探索 next_nodes = [[] for _ in range(V)] for i in range(E): a, b = ab[i] no_cycle_flg = 1 if i in not_cycle else 0 next_nodes[a].append((b, no_cycle_flg)) next_nodes[b].append((a, no_cycle_flg)) queue = [] fix = [MAX_INT ] * V seen = [MAX_INT] * V seen[0] = S - 1 heapq.heappush(queue, (0, S- 1)) while len(queue) > 0: cost, v = heapq.heappop(queue) if fix[v] < MAX_INT: continue fix[v] = cost for w, no_cycle_flg in next_nodes[v]: if fix[w] < MAX_INT: continue new_cost = E ** 2 + cost + no_cycle_flg if seen[w] > new_cost: seen[w] = new_cost heapq.heappush(queue, (new_cost, w)) if fix[G - 1] == MAX_INT: print(-1) else: x = fix[G - 1] ans1 = x // (E ** 2) ans2 = x % (E ** 2) print(ans1 - ans2) if __name__ == "__main__": main()