/*
   Author   : MatsuTaku
   Date     : 01/30/21
*/

#include <bits/stdc++.h>
using namespace std;
#include <x86intrin.h>
#ifndef ONLINE_JUDGE
#define Assert(cond)      assert(cond)
#else
#define Assert(cond)
#endif
#define rep(i, n)         for (size_t i = 0, i##_len = (n); i < i##_len; i++)
using lint = long long int;
template<typename T>
using vvec = vector<vector<T>>;
template<typename T>
vvec<T> make_vvec(int n, int m, T v) { return vvec<T>(n, vector<T>(m, v)); }
template<typename T>
void chmax(T& dst, T x) { dst = max(dst, x); }
template<typename T>
void chmin(T& dst, T x) { dst = min(dst, x); }

class Solver {
 public:
  Solver();
  void solve();
};

Solver::Solver() {}

void Solver::solve() {
  int n,m; cin>>n>>m;
  vector<pair<int,int>> AB(m);
  rep(i, m) {
    int a,b; cin>>a>>b; a--; b--;
    AB[i] = {a,b};
  }
  int k; cin>>k;
  vector<pair<int,int>> CD(k);
  rep(i, k) {
    int c,d; cin>>c>>d; c--; d--;
    CD[i] = {c,d};
  }
  int ans = 0;
  rep(mask, 1<<k) {
    vector<int> C(n);
    rep(i, k) {
      if (mask&(1<<i)) {
        C[CD[i].first]++;
      } else {
        C[CD[i].second]++;
      }
    }
    int sat = 0;
    for (auto [a,b] : AB) {
      if (C[a] > 0 and C[b] > 0)
        sat++;
    }
    chmax(ans, sat);
  }
  cout << ans << endl;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  Solver solver;
  int t = 1;
//  cin>>t;
  while (t--) {
    solver.solve();
  }
  return 0;
}

#include<bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
//const int mod=998244353;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
VL dx={1,0,-1,0};
VL dy={0,1,0,-1};
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
vector<VL> adj;
VL visit2,lefti,righti;
int comp;
ll a,b;
void dfs(int v)
{
    a+=lefti[v];
    b+=righti[v];
    visit2[v]=1;
    for(auto to:adj[v])
    {
        if(visit2[to]==0)
        {
            dfs(to);
        }
    }
    return;
}
void solve()
{
    ll n,m;
    cin>>n>>m;
   
    lefti.assign(n,0);
    righti.assign(n,0);
    fr(i,0,n)
    {
        cin>>lefti[i];
    }
    fr(j,0,n)
    {
        cin>>righti[j];
    }
    comp=0;
    bool ans=true;
    adj.assign(n,VL());
    visit2.assign(n,0);
    fr(i,0,m)
    {
        ll x,y;
        cin>>x>>y;
        x--,y--;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    fr(i,0,n)
    {
        if(visit2[i]==0)
        {
            a=0;b=0;
            dfs(i);
            if(a!=b)
            {
                ans=false;
            }
        }
    }
   // ll ans=true;
    if(a!=b)
    {
        ans=false;
    }
    fr(i,0,n)
    {
        if(visit2[i]==0)
        {
            ans=false;
        }
    }
    if(ans)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return;
}
int main()
{
    IOS;
    ll t=1,pp;
    //cin>>t;
    pp=t;
    while(t--)
    {
        //cout<<"Case #"<<pp-t<<": ";
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
        * BE CAREFUL REGARDING THE DEFAULT VALUES IN segement trees etc
        * BE very careful in int vs long long vs unsigned long long 
*/
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithmQ