#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <unordered_map>
#include <numeric>

#define fore(i, l, r) for(int i = int(l); i < int(r); i++) //Python style baby
#define sz(a) int((a).size())
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vpi vector<pair<int, int>>
#define vl vector<long long>
#define vpl vector<pair<long long, long long>>

using namespace std;
using ll = long long;
int mode, t;

const int N = 101;

int total(vpi &queries, vpi &choices, int k, int code) {
  int hits[N] = {};
  fore (i, 0, k) {
    if (code & 1) {
      hits[choices[i].first]++;
    } else {
      hits[choices[i].second]++;
    }
    code /= 2;
  }

  int ans = 0;
  for (auto ab : queries) {
    if (hits[ab.first] > 0 && hits[ab.second] > 0) {
     ans++;
    } 
  }
  return ans;
}

void solve() {
  int n, m;
  cin >> n >> m;
  vpi queries;
  int a, b;
  fore (i, 0, m) {
    cin >> a >> b;
    queries.pb(mp(a,b)); 
  }
  
  int k;
  cin >> k;
  vpi choices;
  fore (i, 0, k) {
    cin >> a >> b;
    choices.pb(mp(a,b));
  }

  int ans = 0;
  fore (i, 0, 1<<k) {
    ans = max(ans, total(queries, choices, k, i));
  }

  cout << ans << endl;

}



int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  mode = 0;
  if (mode == 0) { 
    solve();
  } else {
    cin >> t;
    while (t--) {
      solve();
    }
  }
}

# include <bits/stdc++.h>
# pragma GCC optimize("Ofast")
# pragma GCC target("avx,avx2,fma")
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    string s;
    int n;
    int q;
    cin >> n;
    cin >> s;
    cin >> q;
    int t, a, b;
    int start = 0;
    while(q--){
        cin >> t >> a >> b;
        --a;
        --b;
        if(t == 1){
            if(start){
                a += (start);
                b += (start);
            }
                swap(s[a % (2*n)], s[b % (2*n)]);
        } else {
            start = (start == n) ? 0 : n;
        }
    }

    if(!start){
        cout << s;
        return 0;
    }

    for(int i = start; i < s.size(); ++i){
        cout << s[i];
    }
    for(int i = 0; i < start; ++i){
        cout << s[i];
    }
    return 0;
}