//#pragma GCC optimize("O3") #include using namespace std; #define ll long long #define rep(i,n) for (ll i=0;i<(ll)n;i++) #define rrep(i,n) for (ll i=n-1;i>=(ll)0;i--) #define loop(i,m,n) for(ll i=m;i<=(ll)n;i++) #define rloop(i,m,n) for(ll i=m;i>=(ll)n;i--) #define vl vector #define vvl vector> #define vdbg(a) rep(ii,a.size()){cout< //#define bbi boost::multiprecision::cpp_int //#include //整数同士の累乗の計算をする。 ll power(ll A, ll B) { ll result = 1; for (ll i=0;i 0){ if ((k&1) ==1)result=(result*n)%mod; n=n*n%mod; k >>= 1; } return result; } //受け取った2次元文字の外側に、文字pをコーティングする。 vector pad(vector &s,char p){ ll h=s.size(); ll w=s[0].size(); vector res(h+2,string(w+2,p)); rep(i,h)rep(j,w)res[i+1][j+1]=s[i][j]; return res; } // Union-Find struct UnionFind { vector par, siz; UnionFind(int n) : par(n, -1) , siz(n, 1) { } // 根を求める int root(int x) { if (par[x] == -1) return x; else return par[x] = root(par[x]); } // x と y が同じグループに属するかどうか (根が一致するかどうか) bool issame(int x, int y) { return root(x) == root(y); } // x を含むグループと y を含むグループとを併合する bool unite(int x, int y) { x = root(x), y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); par[y] = x; siz[x] += siz[y]; return true; } // x を含むグループのサイズ int size(int x) { return siz[root(x)]; } }; //グリッド問題等用 vl dx={1,0,-1,0}; vl dy={0,1,0,-1}; //メイン int main(){ ll n,m; cin>>n>>m; vvl g(n); rep(i,m){ ll u,v; cin>>u>>v; u--,v--; g[u].push_back(v); g[v].push_back(u); } ll k; cin>>k; unordered_set s; rep(i,k){ ll ss; cin>>ss; ss--; s.insert(ss); } vvl dist(n,vl(5,inf)); dist[0][0]=0; queue> bfs; bfs.push({0,0}); while(!bfs.empty()){ ll node,renzoku; node=bfs.front().first; renzoku=bfs.front().second; bfs.pop(); rep(i,g[node].size()){ ll nnode=g[node][i]; ll nrenzoku; if(s.count(nnode))nrenzoku=renzoku+1; else nrenzoku=0; if(nrenzoku==5)continue; if(dist[nnode][nrenzoku]==inf){ dist[nnode][nrenzoku]=dist[node][renzoku]+1; bfs.push({nnode,nrenzoku}); } } } ll ans=inf; rep(i,5){ ans=min(dist[n-1][i],ans); } if(ans==inf)cout<<-1<