/*
Author: QAQAutomaton
Lang: C++
Code: F.cpp
Mail: lk@qaq-am.com
Blog: https://www.qaq-am.com/
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<double> cp;
typedef pair<int,int> pii;
int inf;
const double eps=1e-8;
const double pi=acos(-1.0);
template<class T,class T2>int chkmin(T &a,T2 b){return a>b?a=b,1:0;}
template<class T,class T2>int chkmax(T &a,T2 b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T,class T2>T mmin(T a,T2 b){return a<b?a:b;}
template<class T,class T2>T mmax(T a,T2 b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
template<class T>int dcmp(T a,T b){return a>b;}
template<int *a>int cmp_a(int x,int y){return a[x]<a[y];}
#define min mmin
#define max mmax
#define abs aabs
struct __INIT__{
	__INIT__(){
		memset(&inf,0x3f,sizeof(inf));
	}
}__INIT___;
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	template<typename A>
	inline bool read (A &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;else if(c==EOF)return 0;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
		return 1;
	}
	inline bool read (char &x) {
		while((x=gc())==' '||x=='\n' || x=='\r');
		return x!=EOF;
	}
	inline bool read(char *x){
		while((*x=gc())=='\n' || *x==' '||*x=='\r');
		if(*x==EOF)return 0;
		while(!(*x=='\n'||*x==' '||*x=='\r'||*x==EOF))*(++x)=gc();
		*x=0;
		return 1;
	}
	template<typename A,typename ...B>
	inline bool read(A &x,B &...y){
		return read(x)&&read(y...);
	}
	template<typename A>
	inline bool write (A x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
		return 0;
	}
	inline bool write (char x) {
		putc(x);
		return 0;
	}
	inline bool write(const char *x){
		while(*x){putc(*x);++x;}
		return 0;
	}
	inline bool write(char *x){
		while(*x){putc(*x);++x;}
		return 0;
	}
	template<typename A,typename ...B>
	inline bool write(A x,B ...y){
		return write(x)||write(y...);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: read;
using io :: putc;
using io :: write;
bitset<2005> f[2005],b,s,sub[2005],tof[2005];
pii q[4000005],*l,*r;
vector<int> to[2005];
int dfn[2005],low[2005],t,fa[2005];
int lca[2005][2005],id[2005],tf[2005][2005];
int n,m,u,v;
void dfs(int x,int f){
	fa[x]=f;
	if(f){
		tof[x]=tof[f];
		tof[x].set(f);
	}
	id[dfn[x]=++t]=x;
	for(auto i:to[x])if(i!=f)dfs(i,x);
	low[x]=t;
}
void dfs2(int x,int f,int y,int l){
	lca[x][y]=l;	
	for(auto i:to[x])if(i!=f){
		if(i==fa[x])dfs2(i,x,y,fa[x]);
		else dfs2(i,x,y,l);
	}
}
void init(){
	dfs(1,0);
	for(int i=1;i<=n;++i){
		for(int j=dfn[i];j<=low[i];++j)sub[i][id[j]]=1;
	}
	for(int i=1;i<=n;++i){
		dfs2(i,0,i,i);
	}
	for(int i=1;i<=n;++i){
		for(int j=i,k=i;j;k=j,j=fa[j])tf[i][j]=k;
	}
}
signed main(){
#ifdef QAQAutoMaton 
	freopen("F.in","r",stdin);
	freopen("F.out","w",stdout);
#endif
	read(n,m);
	for(int i=1;i<n;++i){
		read(u,v);
		to[u].push_back(v);
		to[v].push_back(u);
	}
	init();
	for(int i=1;i<=n;++i)f[i].set(i);
	l=q+1;r=q;
	for(int i=1;i<=m;++i){
		read(u,v);
		f[u].set(v);
		f[v].set(u);
		*(++r)=make_pair(u,v);
	}
	for(int i=1;i<=n;++i)s.set(i);
	while(l<=r){
		u=l->x;v=l->y;	
		++l;
		if(dfn[u]>dfn[v])swap(u,v);
		if(low[u]>=low[v]){
			b=s^sub[tf[v][u]]^sub[v]^tof[u]^tof[v];				
		/*	write(u,' ',v,'!');
			for(int j=1;j<=n;++j)if(b[j])write(j,'?');
			write('\n');*/
		}
		else{
			b=sub[u]^sub[v]^tof[u]^tof[v];			
			b.set(lca[u][v]);
			/*
			write(u,' ',v,'x');
			for(int j=1;j<=n;++j)if(b[j])write(j,'?');
			write('\n');*/
		}
		b&=(f[u]^f[v]);
		while(b.any()){
			int x=b._Find_first();
			b[x]=0;
			if(!f[u][x]){
				f[u][x]=f[x][u]=1;
				*(++r)=make_pair(u,x);
			}
			else{
				f[v][x]=f[x][v]=1;
				*(++r)=make_pair(v,x);
			}
		}
	}
	write(r-q,'\n');
	return 0;
}



Measured memory_bytes: 55680