#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,M; cin >> N >> M; vector> Graph(N); for(int i=0; i> u >> v; u--; v--; Graph.at(u).push_back(v); Graph.at(v).push_back(u); } int L; cin >> L; vector NG(N,-1); while(L--){ int j,k; cin >> j >> k; NG.at(j-1) = max(NG.at(j-1),k); } priority_queue> Q; for(int i=0; i= 0) Q.push({NG.at(i),i}); while(Q.size()){ auto [d,pos] = Q.top(); Q.pop(); if(NG.at(pos) != d) continue; if(d == 0) continue; for(auto to : Graph.at(pos)) if(NG.at(to) < d-1) NG.at(to) = d-1,Q.push({d-1,to}); } if(NG.at(0) >= 0){cout << "No\n"; return 0;} vector dist(N,-1); dist.at(0) = 0; queue q; q.push(0); while(q.size()){ int pos = q.front(); q.pop(); for(auto to : Graph.at(pos)) if(NG.at(to) == -1 && dist.at(to) == -1) dist.at(to) = dist.at(pos)+1,q.push(to); } if(dist.at(N-1) == -1) cout << "No\n"; else cout << "Yes\n" << dist.at(N-1) << endl; }