#include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } struct io_setup { io_setup() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); } } io_setup; void solve() { int n, m; cin >> n >> m; vector> g(n); rep(i, 0, m) { int u, v; cin >> u >> v; u--, v--; g[u].push_back(v); g[v].push_back(u); } int k; cin >> k; vector wall(n, 0); rep(i, 0, k) { int a; cin >> a; a--; wall[a] = 1; } vector> dist(5, vector(n, -1)); dist[0][0] = 0; vector> vp = {{0, 0}}; rep(i, 0, vp.size()) { auto [d, nw] = vp[i]; if (nw == n - 1) { cout << dist[d][nw] << "\n"; return; } for (int nx : g[nw]) { int nd = d; if (wall[nx]) nd++; else nd = 0; if (nd >= 5) continue; if (dist[nd][nx] != -1) continue; dist[nd][nx] = dist[d][nw] + 1; vp.push_back({nd, nx}); } } cout << "-1\n"; } int main() { int t = 1; // cin >> t; while (t--) solve(); }