#include <bits/stdc++.h>
#include <type_traits>
using namespace std;

using ll=long long;
//#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) FOR(i,0,b)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
auto& errStream=cerr;
#ifdef LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))
#define fs first
#define sc second

template<class T> using V=vector<T>;
template<class T> using VV=V<V<T>>;

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	rep(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

template<int i,class T>
void print_tuple(ostream&,const T&){
}

template<int i,class T,class H,class ...Args>
void print_tuple(ostream&os,const T&t){
	if(i)os<<",";
	os<<get<i>(t);
	print_tuple<i+1,T,Args...>(os,t);
}

template<class ...Args>
ostream& operator<<(ostream&os,const tuple<Args...>&t){
	os<<"(";
	print_tuple<0,tuple<Args...>,Args...>(os,t);
	return os<<")";
}

ll read(){
	ll i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

template<class T>
void print(const vector<T>&v,int suc=1){
	rep(i,v.size())
		print(v[i],i==int(v.size())-1?suc:2);
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

constexpr ll TEN(int n){
	return n==0?1:TEN(n-1)*10;
}

template<class T>
vector<T> Uniqued(const vector<T>&vv){
	auto v(vv);
	sort(all(v));
	v.erase(unique(all(v)),v.end());
	return v;
}
template<class T>
void MakeUniqued(vector<T>&v){
	sort(all(v));
	v.erase(unique(all(v)),v.end());
}

const int Nmax=2005;
using B=bitset<Nmax>;

vi tr[Nmax];

B ok[Nmax*Nmax/2],sub[Nmax];

void dfs1(int v,int p){
	sub[v].reset();
	sub[v][v]=1;
	for(auto to:tr[v])if(to!=p){
		dfs1(to,v);
		sub[v]|=sub[to];
	}
}

int idx(int a,int b){
	if(a<b)swap(a,b);
	return a*(a+1)/2+b;
}
void dfs2(int rt,int v,int p,B&b){
	if(rt>=v)
		ok[idx(rt,v)]=b;
	for(auto to:tr[v])if(to!=p)
		b^=sub[to];
	for(auto to:tr[v])if(to!=p){
		b^=sub[to];
		dfs2(rt,to,v,b);
		b^=sub[to];
	}
	for(auto to:tr[v])if(to!=p)
		b^=sub[to];
}

void InitOK(int rt){
	dfs1(rt,-1);
	ok[idx(rt,rt)].set();
	for(auto to:tr[rt])
		dfs2(rt,to,rt,ok[idx(rt,rt)]);
}

B g[Nmax],rg[Nmax];
queue<pi> q;
int ans=0;
void push(int a,int b){
	ans++;
	rep(_,2){
		g[a][b]=1;
		rg[a][b]=0;
		swap(a,b);
	}
	q.push(pi(a,b));
}
void ae(int a,int b){
	rep(_,2){
		B w=g[a]&rg[b]&ok[idx(a,b)];
		for(int i=w._Find_first();i<int(w.size());i=w._Find_next(i))
			push(b,i);
		swap(a,b);
	}
}

signed main(){
	bool dbg=false;
	int n=read(),m=read();
	if(n==-1){
		dbg=true;
		n=2000;
	}
	rep(_,n-1){
		int a,b;
		if(dbg){
			a=_;
			b=_+1;
		}else{
			a=read()-1,b=read()-1;
		}
		tr[a].pb(b);
		tr[b].pb(a);
	}
	rep(i,n)
		InitOK(i);
	rep(i,n)rep(j,n)if(i!=j)
		rg[i][j]=1;
	mt19937 rnd(2434);
	rep(_,m){
		int c,d;
		if(dbg){
			/*do{
				c=rnd()%n;
				d=rnd()%n;
			}while(c==d);*/
			c=_;
			d=_+1;
			c%=n;
			d%=n;
		}else{
			c=read()-1,d=read()-1;
		}
		push(c,d);
	}
	while(q.size()){
		pi w=q.front();q.pop();
		ae(w.first,w.second);
	}
	print(ans);
}


Measured memory_bytes: 522676