#include static inline constexpr std::vector> prepare_graph(const uint_fast32_t N, const std::vector>& edges) noexcept { std::vector> next_of(N + 1); for (const auto& [u, v] : edges) next_of[u].push_back(v), next_of[v].push_back(u); return next_of; } static inline constexpr std::vector prepare_creature(const uint_fast32_t N, const std::vector& A) noexcept { std::vector is_there_creature(N + 1, false); for (const auto& a : A) is_there_creature[a] = true; return is_there_creature; } static inline int_fast32_t solve(const uint_fast32_t N, const std::vector>& next_of, const std::vector& is_there_creature) noexcept { std::vector> dist(N + 1, { UINT_FAST32_MAX, UINT_FAST32_MAX, UINT_FAST32_MAX, UINT_FAST32_MAX, UINT_FAST32_MAX }); std::queue> q; dist[1][0] = 0, q.emplace(1, 0); while (!q.empty()) { const auto& [cur_pos, cur_state] = q.front(); for (const auto& next : next_of[cur_pos]) { if (is_there_creature[next]) { if (cur_state < 4 && dist[next][cur_state + 1] == UINT_FAST32_MAX) dist[next][cur_state + 1] = dist[cur_pos][cur_state] + 1, q.emplace(next, cur_state + 1); } else if (dist[next][0] == UINT_FAST32_MAX) dist[next][0] = dist[cur_pos][cur_state] + 1, q.emplace(next, 0); } q.pop(); } return dist[N][0]; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); uint_fast32_t N, M, K; std::cin >> N >> M; std::vector> edges(M); for (auto& [u, v] : edges) std::cin >> u >> v; std::cin >> K; std::vector A(K); for (auto& a : A) std::cin >> a; std::cout << solve(N, prepare_graph(N, edges), prepare_creature(N, A)) << '\n'; return 0; }