n, m, s, t = list(map(int, input().split())) s, t = s-1, t-1 node = [[] for _ in range(n)] V = [0] * n E = [1] * m for _ in range(m): u, v = list(map(lambda x: int(x)-1, input().split())) node[u].append((v, _)) node[v].append((u, _)) V[u] += 1 V[v] += 1 S = [i for i in range(n) if V[i] == 1] while S: now = S.pop() for nxt, idx in node[now]: if not E[idx]: continue E[idx] = 0 V[now] -= 1 V[nxt] -= 1 if V[nxt] == 1: S.append(nxt) D = [-1 for _ in range(n)] F = [-1] * n B = [s] D[s] = 0 F[s] = 0 while A := B: B = [] for now in A: cnt = F[now] for nxt, idx in node[now]: ncnt = cnt + E[idx] if D[nxt] == -1: D[nxt] = D[now] + 1 B.append(nxt) F[nxt] = ncnt elif D[nxt] == D[now] + 1: F[nxt] = max(F[nxt], ncnt) print(F[t])