#include <bits/stdc++.h>

#ifdef __WIN32
#define LLFORMAT "I64"
#else
#define LLFORMAT "ll"
#endif

using namespace std;

constexpr int maxn = 2048;

using u32 = unsigned int;

constexpr u32 pw2[] = {\
	1u << 0, 1u << 1, 1u << 2, 1u << 3, 1u << 4, 1u << 5, 1u << 6, 1u << 7, 1u << 8, 1u << 9, \
		1u << 10, 1u << 11, 1u << 12, 1u << 13, 1u << 14, 1u << 15, 1u << 16, 1u << 17, 1u << 18, 1u << 19, \
		1u << 20, 1u << 21, 1u << 22, 1u << 23, 1u << 24, 1u << 25, 1u << 26, 1u << 27, 1u << 28, 1u << 29, \
		1u << 30, 1u << 31\
};

constexpr u32 MX = pw2[31] | pw2[31] - 1;

struct Item {
	u32 x[maxn >> 5];

	Item() { memset(x, 0, sizeof x); }

	inline void set(int i) { x[i >> 5] |= pw2[i & 31]; }
	inline bool chk(int i) const { return x[i >> 5] & pw2[i & 31]; }
	inline void OR(const Item &a) { for (int i = 0; i < 64; ++i) x[i] |= a.x[i]; return; }
	inline void AND(const Item &a) { for (int i = 0; i < 64; ++i) x[i] &= a.x[i]; return; }
	inline void XOR(const Item &a) { for (int i = 0; i < 64; ++i) x[i] ^= a.x[i]; return; }
};

Item T[maxn], G[maxn], up[maxn], down[maxn << 1];
int f[maxn][maxn], par[maxn], lca[maxn][maxn];

inline Item rev(Item a) {
	for (int i = 0; i < 64; ++i) a.x[i] ^= MX;
	return a;
}

int main() {
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	for (int u = 1; u <= n; ++u) G[u].set(u);
	for (int i = 1; i < n; ++i) {
		int u, v;
		cin >> u >> v;
		T[u].set(v);
		T[v].set(u);
	}
	function<void(int, int)> dfs = [&](int u, int p) {
		up[u] = up[p];
		up[u].set(u);
		down[u].set(u);
		par[u] = p;
		vector<int> all(1, u), tmp;
		for (int v = 1; v <= n; ++v) if((T[u].chk(v) == 1) && v != p) {
			dfs(v, u);
			tmp.clear();
			for (int x = 1; x <= n; ++x) if(down[v].chk(x)) {
				for (int y: all) lca[x][y] = lca[y][x] = u;
				tmp.push_back(x);
			}
			all.insert(all.end(), tmp.begin(), tmp.end());
			down[u].OR(down[v]);
		}
		for (int w = u, v = par[u]; v; v = par[v]) {
			f[u][v] = u + n;
			f[v][u] = w;
			w = v;
		}
		return;
	};
	dfs(1, 0);
	for (int u = 1; u <= n; ++u) down[u + n] = rev(down[u]);
	for (int a = 1; a <= n; ++a) for (int b = 1; b <= n; ++b) if(lca[a][b] != a && lca[a][b] != b) f[a][b] = a + n, f[b][a] = b + n;
	int ans = 0;
	queue<pair<int, int> > q;
	while(m--) {
		int a, b;
		cin >> a >> b;
		++ans;
		G[a].set(b);
		G[b].set(a);
		q.push(make_pair(a, b));
	}
	while(!q.empty()) {
		int a = q.front().first, b = q.front().second;
		q.pop();
		auto F1 = up[a].x, F2 = up[b].x, F3 = up[par[lca[a][b]]].x, F4 = down[f[a][b]].x, F5 = down[f[b][a]].x;
		Item S, T;
		for (int i = 0; i < 64; ++i) S.x[i] = (((F1[i] | F2[i]) ^ F3[i]) | (MX ^ (F4[i] & F5[i])));
		T = rev(G[a]);
		T.AND(G[b]);
		u32 x;
		for (int i = 0; i < 64; ++i) if((x = (S.x[i] & T.x[i]))) {
			while(x) {
				int j = __builtin_ctz(x);
				x ^= pw2[j];
				j |= i << 5;
				if(!G[a].chk(j)) q.push(make_pair(a, j)), G[a].set(j), G[j].set(a), ++ans;
			}
		}
		swap(a, b);
		T = rev(G[a]);
		T.AND(G[b]);
		for (int i = 0; i < 64; ++i) if((x = (S.x[i] & T.x[i]))) {
			while(x) {
				int j = __builtin_ctz(x);
				x ^= pw2[j];
				j |= i << 5;
				if(!G[a].chk(j)) q.push(make_pair(a, j)), G[a].set(j), G[j].set(a), ++ans;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 52276