#include using namespace std; int main() { int N, M; cin >> N >> M; vector dist(N, -1), Watch(N, -1); vector> Graph(N); priority_queue> PQ; for (int i = 0; i < M; i++) { int u, v; cin >> u >> v; Graph.at(u - 1).push_back(v - 1); Graph.at(v - 1).push_back(u - 1); } int L; cin >> L; for (int i = 0; i < L; i++) { int J, K; cin >> J >> K; PQ.push({K, J - 1}); } while (!PQ.empty()) { int J, K; tie(K, J) = PQ.top(); PQ.pop(); if (Watch.at(J) >= K) continue; Watch.at(J) = K; for (int nv : Graph.at(J)) if (K - 1 > Watch.at(nv)) PQ.push({K - 1, nv}); } queue Q; dist.at(0) = 0; if (Watch.at(0) == -1) Q.push(0); while (!Q.empty()) { int v = Q.front(); Q.pop(); for (int nv : Graph.at(v)) { if (dist.at(nv) != - 1 || Watch.at(nv) != -1) continue; dist.at(nv) = dist.at(v) + 1; Q.push(nv); } } cout << (dist.at(N - 1) != -1 ? "Yes" : "No") << endl; if (dist.at(N - 1) != -1) cout << dist.at(N - 1) << endl; }