#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define int long long
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define per(i, a, b) for (ll i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (ll i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter putchar('\n')
#define siz(x) ((ll)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <ll, ll> pii ;
typedef vector <ll> vi ;
typedef vector <pii> vii ;
typedef queue <ll> qi ;
typedef queue <pii> qii ;
typedef set <ll> si ;
typedef map <ll, ll> mii ;
typedef map <string, ll> msi ;
const ll maxn = 5e3 + 100 ;
const ll inf = 0x3f3f3f3f ;
const ll iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll mod = 998244353 ;
const double eps = 1e-7 ;
template <class T = ll> T chmin(T &a, T b) { return a = min(a, b);}
template <class T = ll> T chmax(T &a, T b) { return a = max(a, b);}
template <class T = ll> T read()
{
	T f = 1, a = 0;
	char ch = getchar() ;
	while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
	while (isdigit(ch)) { a =  (a << 3) + (a << 1) + ch - '0' ; ch = getchar() ; }
	return a * f ;
}

ll n, m, ans;

vi edge[maxn];

ll dis[maxn][maxn], pa[maxn][maxn], vis[maxn][maxn];

void dfs(ll top, ll now, ll fa)
{
	pa[top][now] = fa;
	for(ll to : edge[now])
	{
		if(to == fa) continue;
		dis[top][to] = dis[top][now] + 1;
		dfs(top, to, now);
	}
}

vi ret;

void find_edge(ll u, ll v)
{
	ll now = v;
	while(now != u)
	{
		ret.pb(now);
		now = pa[u][now];
	}
	ret.pb(u);
}

si s[maxn];

void remove(ll u, ll v)
{
	// printf("remove : %lld %lld\n", u, v);
	s[u].erase(s[u].find(v));
	s[v].erase(s[v].find(u));
	vis[u][v] = vis[v][u] = 0;
}

void append(ll u, ll v)
{
	s[u].insert(v), s[v].insert(u);
	vis[u][v] = vis[v][u] = 1;
}

void addedge(ll u, ll v)
{
	// printf("addedge : %lld %lld\n", u, v);
	vi().swap(ret);
	find_edge(v, u);
	ll f = u, t = v, pos = 0;
	rep(i, 0, siz(ret) - 1)
	{
		// printf("to : %lld\n", ret[i]);
		if(vis[f][ret[i]]) f = ret[i], pos = i;
	}
	per(i, siz(ret) - 1, pos) if(vis[ret[i]][t]) t = ret[i];
	if(f == t || vis[f][t]) return ;//(void)(puts("pugai"));
	vii ins, del;
	// puts("merge");
	for(ll k : s[f])
	{
		if(dis[f][k] == dis[f][t] + dis[t][k])
		{
			// printf("%lld %lld %lld\n", f, t, k);
			ins.pb(mp(t, k));
			del.pb(mp(f, k));
		}
	}
	for(ll k : s[t])
	{
		if(dis[k][t] == dis[k][f] + dis[f][t])
		{
			// printf("%lld %lld %lld\n", k, f, t);
			ins.pb(mp(k, f));
			del.pb(mp(k, t));
		}
	}
	for(pii i : del) remove(i.fi, i.se);
	vii().swap(del);
	append(f, t);
	for(pii i : ins) addedge(i.fi, i.se);
}

ll g[maxn][maxn];

void find(ll top, ll now)
{
	for(ll to : s[now])
	{
		if(g[top][to]) continue;
		if(dis[top][to] != dis[top][now] + dis[now][to]) continue;
		g[top][to] = 1, ans ++;
		find(top, to);
	}
}

signed main()
{
	n = read(), m = read();
	rep(i, 1, n - 1)
	{
		ll u = read(), v = read();
		edge[u].pb(v), edge[v].pb(u);
		// printf("edge : %lld %lld\n", u, v);
	}
	rep(i, 1, n) dfs(i, i, i);
	// rep(i, 1, n) rep(j, 1, n) printf("%lld%c", dis[i][j], " \n"[j == n]);
	rep(i, 1, m)
	{
		ll u = read(), v = read();
		addedge(u, v);
	}
	rep(i, 1, n) find(i, i);
	printf("%lld\n", ans / 2);
	return 0;
}

Measured memory_bytes: 140844