#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

constexpr int B = 64;
constexpr uint64_t b1 = 1;

void DFS(int R, vector< vector<int> > & G, vector<int> & par, auto & down, auto & B_subtree) {
	B_subtree[R][R/B] |= b1<<(R%B);
	down[R][R] = R;
	ALL_THE(G[R], it) if(par[*it] == -1) {
		par[*it] = R;
		DFS(*it, G, par, down, B_subtree);
		for(int i = 0; i < (int)down[*it].size(); i++)
			if(down[*it][i] != -1) down[R][i] = *it;
		for(int i = 0; i < (int)B_subtree[*it].size(); i++)
			B_subtree[R][i] |= B_subtree[*it][i];
	}
}

void solve_path(int u, int v, auto & B_path, auto & down, auto & par) {
	if(u > v) swap(u, v);
	if(!B_path[u][v].empty()) return;
	if(u == v) {
		B_path[u][u] = vector<uint64_t>(B_path.size()/B+1, 0);
		B_path[u][u][u/B] |= b1<<(u%B);
		return;
	}
	int w = (down[v][u] != -1) ? down[v][u] : par[v];
	solve_path(w, u, B_path, down, par);
	B_path[u][v] = B_path[min(u, w)][max(u, w)];
	B_path[u][v][v/B] |= b1<<(v%B);
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N, M;
	cin >> N >> M;
	vector< vector<int> > T(N);
	for(int i = 0; i < N-1; i++) {
		int u, v;
		cin >> u >> v;
		T[--u].push_back(--v);
		T[v].push_back(u);
	}
	vector<int> par(N, -1);
	vector< vector<uint64_t> > B_subtree(N, vector<uint64_t>(N/B+1, 0));
	vector< vector<int> > down(N, vector<int>(N, -1));
	par[0] = 0;
	DFS(0, T, par, down, B_subtree);
	vector< vector< vector<uint64_t> > > B_path(N, vector< vector<uint64_t> >(N));
	for(int i = 0; i < N; i++) for(int j = 0; j < i; j++)
		solve_path(i, j, B_path, down, par);

	vector< vector<uint64_t> > B_G(N, vector<uint64_t>(N/B+1, 0)); // already added
	vector< vector<uint64_t> > B_E(N, vector<uint64_t>(N/B+1, 0)); // will be added
	for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) if(i != j)
		B_E[i][j/B] |= b1<<(j%B);
	queue< pair<int, int> > q;
	for(int i = 0; i < M; i++) {
		int u, v;
		cin >> u >> v;
		q.push({--u, --v});
		B_E[u][v/B] ^= b1<<(v%B);
		B_E[v][u/B] ^= b1<<(u%B);
	}
	int ans = 0;
	while(!q.empty()) {
		int u = q.front().first, v = q.front().second;
		q.pop();
		ans++;
		if(u > v) swap(u, v);
		if(down[u][v] != -1) {
			int d = down[u][v];
			for(int i = 0; i <= N/B; i++) {
				// in path ..u-..-v..
				uint64_t b = B_path[u][v][i] | (~B_subtree[d][i]) | B_subtree[v][i];
				uint64_t add;
				// u-i exists, adding v-i
				add = b & B_G[u][i] & B_E[v][i];
				if(add != 0) for(int j = 0; j < B; j++) if((add>>j)&1) {
					int w = B * i + j;
					B_E[v][i] ^= b1<<j;
					B_E[w][v/B] ^= b1<<(v%B);
					q.push({w, v});
				}
				// v-i exists, adding u-i
				add = b & B_G[v][i] & B_E[u][i];
				if(add != 0) for(int j = 0; j < B; j++) if((add>>j)&1) {
					int w = B * i + j;
					B_E[u][i] ^= b1<<j;
					B_E[w][u/B] ^= b1<<(u%B);
					q.push({w, u});
				}
			}
		}
		else if(down[v][u] != -1) {
			int d = down[v][u];
			for(int i = 0; i <= N/B; i++) {
				// in path ..u-..-v..
				uint64_t b = B_path[u][v][i] | (~B_subtree[d][i]) | B_subtree[u][i];
				uint64_t add;
				// u-i exists, adding v-i
				add = b & B_G[u][i] & B_E[v][i];
				if(add != 0) for(int j = 0; j < B; j++) if((add>>j)&1) {
					int w = B * i + j;
					B_E[v][i] ^= b1<<j;
					B_E[w][v/B] ^= b1<<(v%B);
					q.push({w, v});
				}
				// v-i exists, adding u-i
				add = b & B_G[v][i] & B_E[u][i];
				if(add != 0) for(int j = 0; j < B; j++) if((add>>j)&1) {
					int w = B * i + j;
					B_E[u][i] ^= b1<<j;
					B_E[w][u/B] ^= b1<<(u%B);
					q.push({w, u});
				}
			}
		}
		else {
			for(int i = 0; i <= N/B; i++) {
				// in path ..u-..-v..
				uint64_t b = B_path[u][v][i] | B_subtree[u][i] | B_subtree[v][i];
				uint64_t add;
				// u-i exists, adding v-i
				add = b & B_G[u][i] & B_E[v][i];
				if(add != 0) for(int j = 0; j < B; j++) if((add>>j)&1) {
					int w = B * i + j;
					B_E[v][i] ^= b1<<j;
					B_E[w][v/B] ^= b1<<(v%B);
					q.push({w, v});
				}
				// v-i exists, adding u-i
				add = b & B_G[v][i] & B_E[u][i];
				if(add != 0) for(int j = 0; j < B; j++) if((add>>j)&1) {
					int w = B * i + j;
					B_E[u][i] ^= b1<<j;
					B_E[w][u/B] ^= b1<<(u%B);
					q.push({w, u});
				}
			}
		}
		B_G[u][v/B] |= b1<<(v%B);
		B_G[v][u/B] |= b1<<(u%B);
	}
	cout << ans << "\n";
}

// look at my code
// my code is amazing


Measured memory_bytes: 659636