#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, s, n) for (ll i = s; i < (n); i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> type(2*n, 0);
  vector<vector<int>> p(2*n, vector<int>(2*n, 0));
  bool check = true;
  rep(i, n){
    int a, b;
    cin >> a >> b;
    if (a != -1){
      a--;
      if (type[a] != 0){
        check = false;
        break;
      }
      type[a] = -1;
    }
    if (b != -1){
      b--;
      if (type[b] != 0){
        check = false;
        break;
      }
      type[b] = 1;
    }
    if (a != -1 && b != -1){
      rep(j, 2*n){
        p[a][j] = -1;
        p[j][a] = -1;
        p[b][j] = -1;
        p[j][b] = -1;
      }
      p[a][b] = 1;
    }
  }
  vector<bool> dp(n+1, false);
  dp[0] = true;
  rep2(i, 1, n+1){
    if (!check) break;
    rep(j, i){
      if (!dp[j]) continue;
      ll dist = i - j;
      bool flag = true;
      rep(k, dist){
        if (p[j*2+k][j*2+k+dist] == -1 ||
            (p[j*2+k][j*2+k+dist] == 0 && type[j*2+k] != 0 && type[j*2+k+dist] != 0) ||
            type[j*2+k] == 1 || type[j*2+k+dist] == -1){
          flag = false;
          break;
        }
      }
      if (flag){
        dp[i] = true;
        break;
      }
    }
  }
  
  if (dp[n]) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i,n) for(int i=0; i<n; ++i)
#define fi(i,st,n) for(int i=st; i<=n; ++i)
#define veci vector<int>
#define vecp vector<pair<int,int> >
#define vecl vector<ll>
int prime[100000+10];

ll lcm(ll a, ll b) {
	return a*b/__gcd(a,b);
}

ll power(ll a, ll n, ll mod) {
	ll res = 1;
	while(n > 0) {
		if(n&1) {
			res = (res*a)%mod;
		}
		a = (a*a)%mod;
		n = n/2;
	}
	return res;
}

ll sum(int arr[], int n) {
	ll res = 0;
	f(i,n) {
		res += arr[i];
	}
	return res;
}

void seive() {
	prime[1] = 0;
	for(int i=2; i<=100000; i++) {
		prime[i] = 1;
	}
	for(ll i=2; i<=100000; i++) {
		if(prime[i]) {
			for(ll j=i*i; j<=100000; j+=i) {
				prime[j] = 0;
			}
		}
	}
}

bool check(string s) {
	f(i,s.length()) {
		if(s[i] == '0') return false;
	}
	return true;
} 

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--){
		ll n,m;
		cin>>n>>m;
		ll a[m],b[m];
		f(i,m) {
			cin>>a[i]>>b[i];
		}
		ll k;
		cin>>k;
		ll c[k],d[k];
		f(i,k) {
			cin>>c[i]>>d[i];
		}
		string s = "";
		f(i,k) s += "0";
		int ans = 0;
		while(true) {
			if(check(s)) break;
			ll temp[n+1] = {0};
			f(i,k) {
				if(s[i] == '0') {
					temp[c[i]]++;
				} else {
					temp[d[i]]++;
				}
			}
			int res = 0;
			f(i,m) {
				
				if(temp[a[i]] and temp[b[i]]) {
					res++;
				}
			}
			ans = max(ans,res);
			f(i,k) {
				if(s[i] == '0') {
					s[i] = '1';
					break;
				}
				else {
					s[i] = '0';
				}
			}
		}
		cout<<ans;
	}
 	return 0;
}
