#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (2010)
#define P ()
#define M (N<<1)
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1{
	inline char read(){
		static const int IN_LEN=1000000;
		static char buf[IN_LEN],*s,*t;
		return (s==t?t=(s=buf)+fread(buf,1,IN_LEN,stdin),(s==t?-1:*s++):*s++);
	}
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=read();!isdigit(c);c=read()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=read())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
	inline char readc(char &c){
		for(c=read();!isalpha(c)&&!isdigit(c);c=read())
		if(c==-1)return 0;
	}
	const int OUT_LEN = 10000000;
	char obuf[OUT_LEN],*ooh=obuf;
	inline void print(char c){
		if(ooh==obuf+OUT_LEN)fwrite(obuf,1,OUT_LEN,stdout),ooh=obuf;
		*ooh++=c;
	}
	template<class T>
	inline void print(T x){
		static int buf[30],cnt;
		if(x==0)print('0');
		else{
			if(x<0)print('-'),x=-x;
			for(cnt=0;x;x/=10)buf[++cnt]=x%10+48;
			while(cnt)print((char)buf[cnt--]);
		}
	}
	inline void flush(){fwrite(obuf,1,ooh-obuf,stdout);}
}
namespace fastIO2{
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=getchar();!isdigit(c);c=getchar()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=getchar())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
}
using namespace fastIO1;
struct node{
	int x,y;
}que[N]; queue<node> Q;
bool vis[N],tag=0,gr[N][N];
int n,m,E,top[N][N],fi[N],ne[M],b[M],ans,cnt,fa[N][N];
void dfs(int u,int s,int e){
	for(int i=fi[u];i;i=ne[i]){
		int v=b[i];
		if(v==fa[s][u])continue;
		if(!top[s][v])top[s][v]=e,dfs(v,s,e);
		else if(gr[s][v]){
			gr[s][v]=gr[v][s]=0;
//			cout<<s<<"<-GG->"<<v<<endl;
			Q.push((node){e,v});
//			cout<<e<<" "<<v<<endl;
		}
	}
}
void dfs2(int u,int rt,int pre){
	fa[rt][u]=pre;
	for(int i=fi[u];i;i=ne[i]){
		int v=b[i];
		if(v==pre)continue;
		dfs2(v,rt,u);
	}
}
void Link(int x,int y);
void solve(int x,int y);
void Link(int x,int y){
//	cout<<x<<"<--1-->"<<y<<endl;
//	tag=0,Delete(x,x,0,y),tag=0,Delete(y,x);
	gr[x][y]=1,top[x][y]=y,dfs(y,x,y),
	gr[y][x]=1,top[y][x]=x,dfs(x,y,x);
	for(int x,y;!Q.empty();){
		
		x=Q.front().x,y=Q.front().y;
//		cout<<x<<"<--resolve-->"<<y<<endl;
		Q.pop(),solve(x,y);
	}
}
void solve(int x,int y){
//	cout<<x<<"<--solve-->"<<y<<endl;
	if(top[x][y]==y||top[y][x]==x)return;
	if(top[x][y])solve(top[x][y],y);
	else if(top[y][x])solve(x,top[y][x]);
	else if(x!=y)Link(x,y);
}
void calc(int u,int t,int rt){
	if(top[t][u]==u)ans++,t=u;
//	cout<<t<<" "<<u<<" "<<top[t][u]<<endl;
	for(int i=fi[u];i;i=ne[i]){
		int v=b[i];
		if(v==fa[rt][u])continue;
		calc(v,t,rt);
	}
}
void add(int x,int y){
	ne[++E]=fi[x],fi[x]=E,b[E]=y;
}
int main(){
//	file("test");
	read(n),read(m);
	for(int i=1;i<n;i++){
		int x,y;
		read(x),read(y);
		add(x,y),add(y,x);
	}
	
	for(int i=1;i<=n;i++)dfs2(i,i,0);
	
	for(int i=1,x,y;i<=m;i++)
	read(x),read(y),solve(x,y); 
	
	for(int i=1;i<=n;i++)
	for(int j=fi[i];j;j=ne[j])calc(b[j],i,i);
	printf("%d\n",ans/2);
}

Measured memory_bytes: 37376