/** Fucc :/
 - doanphuc : /
	** author: doanphuc. **
**/
#include <bits/stdc++.h>
#define TASK ""
#define inpf freopen(TASK".inp", "r", stdin)
#define outf freopen(TASK".out", "w", stdout)
#define FOR(i,x,y) for(int i = x; i <= y ; i ++)
#define FORT(i,x,y) for(int i = x; i < y ; i ++)
#define FORD(i,x,y) for(int i = x; i >= y ; i --)
#define clean(x) memset(x, 0, sizeof(x))
#define F first
#define S second
#define maxn 1000005
#define pii pair<ll,ll>
#define ll long long
#define pb push_back
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define all(x) (x).begin(), (x).end()
#define pia pair<pii, int>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const ll MOD = 1e9 + 7 ;
ll n, c, e, tr[maxn] ;
vector<int> a[maxn] ;
void dfs(int u)
{
    if(tr[u]) return ;
    tr[u] = 1 ;
    c ++ ; e += a[u].size() ;
    for(auto v: a[u]) dfs(v) ;
}
int main()
{
//    inpf; outf; fast;
    cin >> n ;
    FOR(i, 1, n)
    {
        int u, v ;
        cin >> u >> v ;
        a[u].pb(v) ; a[v].pb(u) ;
    }
    ll ans = 0 ;
    FORT(i, 1, maxn)
    {
        if(tr[i]) continue ;
        c = e = 0 ;
        dfs(i);
        ans += min(c, e / 2) ;
    }
    cout << ans ;


}

//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*                                                    
      I ♥ CLARICE STARLING...                                                               
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
int n,m,k,ans;
vector<int>a,b,c,d,dish;
void recursion(int pos)
{
    int i;
    if(pos==k)
    {
        int cnt=0;
        fo(i,0,m)
        {
          if(dish[a[i]]&&dish[b[i]])cnt++;  
        }
        ans=max(ans,cnt);
    }
    else
    {
        i=pos;
        dish[c[i]]++;recursion(pos+1);dish[c[i]]--;
        dish[d[i]]++;recursion(pos+1);dish[d[i]]--;
    }
}
void solve()
{
   int i;cin>>n>>m;
   dish=vector<int>(n,0);
   a=b=vector<int>(m);
   fo(i,0,m){cin>>a[i]>>b[i];a[i]--;b[i]--;}
   cin>>k;
   c=d=vector<int>(k);
   fo(i,0,k){cin>>c[i]>>d[i];c[i]--;d[i]--;}
   
   recursion(0);
   cout<<ans<<"\n";
}
int main()
{
   fastio
   //Test_cases
   solve();
  return 0;
}
