#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    vector<int> B(M);
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
    }
    int K;
    cin >> K;
    vector<int> C(K + 1);
    vector<int> D(K + 1);
    for (int i = 0; i < K; i++) {
        cin >> C[i] >> D[i];
    }
    int ans = -1;
    for (int i = 0; i < (1 << K); i++) {
        vector<int> save(N + 1);
        for (int j = 0; j < K; j++) {
            if (i & (1 << j)) save.at(C.at(j))++;
            else save.at(D.at(j))++;
        }
        int cnt = 0;
        for (int j = 0; j < M; j++) {
            if (save.at(A.at(j)) > 0 && save.at(B.at(j)) > 0) cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}   
#include<bits/stdc++.h>
#define ll long long
#define pi 3.1415926535897932384626
using namespace std;
  
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(x!=a.x) return x<a.x;
    //if(y!=a.y)
    return x>a.x;
  };
};
 
int a,b,c,d,i,n,m,e,k,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[211111];
int l[201011],ck[201010];
ll dp[2];
int ss[201011];
int ans[1];

long long x,y,z;
const long long mod=1000000007,hf=(mod+1)/2;
  
  

//string r;
char r;
vector<int> v[201011];
P u[201011];
queue<P> q;
  
  
//multiset<int> s;
stack<int> s;
unordered_map<int,int> p[1];
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//rng()
bool as(P a,P b)
{
  //if(a.x!=b.x)
  //return a.x<b.x;
  //if(a.y!=b.y) return a.y>b.y;
  return min(a.x,a.y)<min(b.x,b.y);
}


int main()
{
  scanf("%d %d",&a,&b);
  for(int t=1;t<a;t++)
  {
    scanf("%d %d",&n,&m);
    v[n].push_back(m);
    v[m].push_back(n);
  }
  n=1,m=a;
  for(;n<m;)
  {
    int k=(n+m)/2;
    e=0;
    queue<int> q;
    memset(ss,0,sizeof(ss));
    memset(l,-1,sizeof(l));
    memset(o,0,sizeof(o));
    memset(ck,0,sizeof(ck));
    for(int t=1;t<=a;t++)
    if(v[t].size()==1)
    {
      l[t]=-1;
      //ck[t]=1;
      q.push(t);
    }
    int r=0;
    for(;q.size();q.pop())
    {
      int p=q.front();
      //printf("#%d\n",p);
      ck[p]=1;
      r++;
      if(-l[p]>o[p])
      {
        if(-l[p]>k)
        {
          //printf("**%d\n",p);
          e++;
          for(int h=0;h<v[p].size();h++)
          if(ck[v[p][h]]==0)
          {
            ss[v[p][h]]++;
            o[v[p][h]]=max(o[v[p][h]],k);
            if(ss[v[p][h]]+1==v[v[p][h]].size())
            {
              //ck[v[p][h]]=1;
              q.push(v[p][h]);
            }
          }
        }
        else if(r==a) e++;
        else
        {
          for(int h=0;h<v[p].size();h++)
          if(ck[v[p][h]]==0)
          {
            //printf("^^%d\n",v[p][h]);
            ss[v[p][h]]++;
            l[v[p][h]]=min(l[v[p][h]],l[p]-1);
            if(ss[v[p][h]]+1==v[v[p][h]].size())
            {
              //ck[v[p][h]]=1;
              q.push(v[p][h]);
            }
          }
        }
      }
      else
      {
        for(int h=0;h<v[p].size();h++)
          if(ck[v[p][h]]==0)
          {
            ss[v[p][h]]++;
            if(o[p]>0) o[v[p][h]]=max(o[v[p][h]],o[p]-1);
            //else l[v[p][h]]=min(l[v[p][h]],-1);
            if(ss[v[p][h]]+1==v[v[p][h]].size())
            {
              //ck[v[p][h]]=1;
              q.push(v[p][h]);
            }
          }
      }
    }
    
    if(e<=b) m=k;
    else n=k+1;
    
  }
  //printf("%d %d %d\n",n,m,e);
  //for(int t=1;t<=a;t++)
    //printf("#%d %d\n",l[t],o[t]);
  printf("%d",n);
}
/*
7 2
1 2
2 3
3 4
4 5
5 6
6 7
 */
