#include using namespace std; using ll = long long; using pll = pair; #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); const ll MOD1000000007 = 1000000007; const ll MOD998244353 = 998244353; const ll MOD[3] = {999727999, 1070777777, 1000000007}; const ll LINF = 1LL << 60LL; const int IINF = (1 << 30) - 1; void solve(){ int N, M; cin >> N >> M; vector> G(N); for(int i=0; i> u >> v; u--; v--; G[u].push_back(v); G[v].push_back(u); } vector check(N, false); int K; cin >> K; for(int i=0; i> a; check[a-1] = true; } vector> dist(N, vector(5, -1)); queue> que; dist[0][0] = 0; que.push({0, 0}); while(!que.empty()){ auto [v, cnt] = que.front(); que.pop(); for(int to : G[v]){ if(check[to]){ if(cnt < 4){ if(dist[to][cnt+1] != -1) continue; dist[to][cnt+1] = dist[v][cnt] + 1; que.push({to, cnt+1}); } }else{ if(dist[to][0] != -1) continue; dist[to][0] = dist[v][cnt] + 1; que.push({to, 0}); } } } int ans = IINF; for(int i=0; i<5; i++){ if(dist[N-1][i] != -1) ans = min(ans, dist[N-1][i]); } if(ans == IINF) cout << -1 << "\n"; else cout << ans << endl; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int T=1; //cin >> T; while(T--) solve(); }