#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using Int = long long; template ostream &operator<<(ostream &os, const pair &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } //////////////////////////////////////////////////////////////////////////////// namespace nim { using u16 = unsigned short; using u32 = unsigned; using u64 = unsigned long long; template inline u64 mulSlow(u64 a, u64 b) { static constexpr int l = L >> 1; const u64 a0 = a & ((1ULL << l) - 1), a1 = a >> l; const u64 b0 = b & ((1ULL << l) - 1), b1 = b >> l; const u64 a0b0 = mulSlow(a0, b0); return (a0b0 ^ mulSlow(1ULL << (l - 1), mulSlow(a1, b1))) | (a0b0 ^ mulSlow(a0 ^ a1, b0 ^ b1)) << l; } template <> inline u64 mulSlow<1>(u64 a, u64 b) { return a & b; } constexpr u16 G16 = 10279U; u16 buf[4 * ((1 << 16) - 1) + 26]; u16 *exp = buf + (2 * ((1 << 16) - 1) + 18), *exp3 = exp + 3, *exp6 = exp + 6; int log[1 << 16]; struct Preparator { Preparator() { exp[0] = 1; for (int i = 1; i < (1 << 16) - 1; ++i) exp[i] = mulSlow<16>(exp[i - 1], G16); log[0] = -(((1 << 16) - 1) + 9); for (int i = 0; i < (1 << 16) - 1; ++i) log[exp[i]] = i; memcpy(exp + ((1 << 16) - 1), exp, ((1 << 16) - 1) * sizeof(u16)); memcpy(exp + 2 * ((1 << 16) - 1), exp, 8 * sizeof(u16)); } } preparator; inline u16 mul(u16 a, u16 b) { return exp[log[a] + log[b]]; } inline u32 mul(u32 a, u32 b) { const u16 a0 = a, a1 = a >> 16; const u16 b0 = b, b1 = b >> 16; const u16 a01 = a0 ^ a1; const u16 b01 = b0 ^ b1; const u16 a0b0 = mul(a0, b0); return (a0b0 ^ exp3[log[a1] + log[b1]]) | (u32)(a0b0 ^ mul(a01, b01)) << 16; } inline u64 mul(u64 a, u64 b) { u64 aa = a >> 16, aaa = a >> 32; u64 bb = b >> 16, bbb = b >> 32; const u16 a0 = a, a1 = aa, a2 = aaa, a3 = a >> 48; const u16 b0 = b, b1 = bb, b2 = bbb, b3 = b >> 48; aa ^= a; aaa ^= a; bb ^= b; bbb ^= b; const u16 a01 = aa, a23 = aa >> 32, a02 = aaa, a13 = aaa >> 16; const u16 b01 = bb, b23 = bb >> 32, b02 = bbb, b13 = bbb >> 16; const u16 a0123 = a01 ^ a23; const u16 b0123 = b01 ^ b23; const u16 a0b0 = mul(a0, b0), a23b23 = mul(a23, b23), a02b02 = mul(a02, b02); const u32 c = (a0b0 ^ exp3[log[a1] + log[b1]]) | (u32)(a0b0 ^ mul(a01, b01)) << 16; return (c ^ (exp6[log[mul(a2, b2) ^ a23b23]] | (u32)exp3[log[exp3[log[a3] + log[b3]] ^ a23b23]] << 16)) | (u64)(c ^ ((a02b02 ^ exp3[log[a13] + log[b13]]) | (u32)(a02b02 ^ mul(a0123, b0123)) << 16)) << 32; } } // namespace nim //////////////////////////////////////////////////////////////////////////////// unsigned xrand() { static unsigned x = 314159265, y = 358979323, z = 846264338, w = 327950288; unsigned t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8; } using namespace nim; constexpr int MAX_N = 110; int N, M; int X, Y, Z; vector A, B; bool adj[MAX_N][MAX_N]; u64 C[MAX_N][MAX_N]; u64 dp[MAX_N][4][MAX_N]; u64 dpY[MAX_N][4][MAX_N]; u64 dpZ[MAX_N][4][MAX_N]; int main() { for (; ~scanf("%d%d", &N, &M); ) { scanf("%d%d%d", &X, &Y, &Z); --X; --Y; --Z; A.resize(M); B.resize(M); for (int i = 0; i < M; ++i) { scanf("%d%d", &A[i], &B[i]); --A[i]; --B[i]; } memset(adj, 0, sizeof(adj)); for (int u = 0; u < N; ++u) for (int v = 0; v < N; ++v) { adj[u][v] = (u != v); } for (int i = 0; i < M; ++i) { adj[A[i]][B[i]] = adj[B[i]][A[i]] = false; } for (int u = 0; u < N; ++u) { adj[N][u] = adj[X][u]; adj[u][N] = adj[u][X]; } int ans = N + 1; for (int iter = 0; iter < 1; ++iter) { memset(C, 0, sizeof(C)); for (int u = 0; u <= N; ++u) for (int v = u + 1; v <= N; ++v) { u64 c = xrand(); c <<= 32; c |= xrand(); C[u][v] = C[v][u] = c; } memset(dp, 0, sizeof(dp)); memset(dpY, 0, sizeof(dpY)); memset(dpZ, 0, sizeof(dpZ)); dp[0][0][X] = 1; for (int l = 0; l < N; ++l) { for (int p = 0; p < 4; ++p) { for (int u = 0; u <= N; ++u) { for (int v = 0; v <= N; ++v) if (adj[u][v]) { const u64 prod = mul(dp[l][p][u], C[u][v]); if (v == Y) { if (!(p & 1)) { dpY[l + 1][p | 1][u] ^= prod; } } else if (v == Z) { if (!(p & 2)) { dpZ[l + 1][p | 2][u] ^= prod; } } else { dp[l + 1][p][v] ^= prod; } } } if (p & 1) { u64 sum = 0; for (int u = 0; u <= N; ++u) { sum ^= dpY[l][p][u]; } for (int u = 0; u <= N; ++u) if (adj[Y][u]) { dp[l + 1][p][u] ^= mul(sum ^ dpY[l][p][u], C[Y][u]); } } if (p & 2) { u64 sum = 0; for (int u = 0; u <= N; ++u) { sum ^= dpZ[l][p][u]; } for (int u = 0; u <= N; ++u) if (adj[Z][u]) { dp[l + 1][p][u] ^= mul(sum ^ dpZ[l][p][u], C[Z][u]); } } } } for (int l = 0; l <= N; ++l) { if (dp[l][3][N]) { chmin(ans, l); } } } printf("%d\n", (ans >= N + 1) ? -1 : ans); } return 0; }