#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define inf 1e18 #define rep(x, s, t) for(int (x) = (s); (x) < (t); (x)++) #define Rep(x, s, t) for(int (x) = (s); (x) <= (t); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) using namespace std; typedef pair P; int n, m, Q; int a[200005], b[200005]; vector vec[200005]; set

S[1000005], S2[1000005]; bool check(int p, int l, int r) { auto it = S[p].lower_bound(P(l, l)); if(it != S[p].end() && it->first <= r) return false; if(it == S[p].begin()) return true; it--; return it->second < l; } int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for(int i = 1; i <= m; i++) cin >> a[i]; cin >> Q; for(int i = 1; i <= Q; i++){ cin >> b[i]; vec[b[i]].push_back(i); } for(int i = 1; i <= m; i++) vec[i].push_back(Q+1); for(int i = 1; i <= m; i++){ int p = a[i]; if(!check(p, 0, vec[i].front()-1)){ cout << "NO" << endl; return 0; } S[p].insert(P(0, (int)vec[i].front()-1)); S2[p].insert(P(0, i)); for(int j = 0; j < (int)vec[i].size()-1; j++){ int l = vec[i][j], r = vec[i][j+1]-1; //cout << i << " " << l << " " << r << endl; bool flag = false; for(int k = -1; k <= 1; k+=2){ int np = p + k; if(np < 1 || np > n) continue; if(k == -1 && S2[p].count(P(l, i-1))) continue; if(check(np, l, r)){ p = np; flag = true; S[np].insert(P(l, r)); S2[np].insert(P(l, i)); //cout << "!" << np << " " << l << " " << r << endl; break; } } if(!flag){ cout << "NO" << endl; return 0; } } } cout << "YES" << endl; return 0; }