#include <bits/stdc++.h>

using namespace std;

const int N = 2103;

int n, m;
int top, fi[N], ne[N << 1], to[N << 1];
int fa[N][N], from[N][N];
bool line[N][N];
int res;
queue<int> q;

void add(int u, int v);
void getfa(int t, int fa, int p);
void buildGraph(int u, int v);
void getres(int t, int fa, int p);

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 2, u, v; i <= n; ++i) {
    scanf("%d%d", &u, &v);
    add(u, v), add(v, u);
  }
  for (int i = 1; i <= n; ++i) getfa(i, 0, i);
  for (int i = 1, u, v; i <= m; ++i) {
    scanf("%d%d", &u, &v);
    buildGraph(u, v);
  }
  for (int i = 1; i <= n; ++i) getres(i, i, i);
  printf("%d\n", res / 2);
  return 0;
}

void add(int u, int v) {
  ne[++top] = fi[u], fi[u] = top, to[top] = v;
}

void getfa(int t, int f, int p) {
  fa[p][t] = f;
  for (int i = fi[t]; i; i = ne[i]) {
    if (to[i] == f) continue;
    getfa(to[i], t, p);
  }
}

void buildGraph(int u, int v) {
  if (from[u][v] == v) return ;
  if (from[u][v]) return buildGraph(from[u][v], v);
  if (from[v][u]) return buildGraph(from[v][u], u);
  line[u][v] = line[v][u] = true;
  from[u][v] = v, from[v][u] = u;

  vector<pair<int, int> > need;

  for (int times = 1; times <= 2; ++times) {
    q.push(v);
    while (!q.empty()) {
      int f = q.front();
      q.pop();
      for (int i = fi[f]; i; i = ne[i]) {
        if (to[i] == fa[u][f]) continue;
        if (from[u][to[i]]) {
          line[from[u][to[i]]][u] = line[u][from[u][to[i]]] = false;
          need.push_back(make_pair(from[u][to[i]], v));
        } else {
          from[u][to[i]] = v;
          q.push(to[i]);
        }
      }
    }
    swap(u, v);
  }

  for (int i = need.size() - 1; i >= 0; --i) 
    buildGraph(need[i].first, need[i].second);
}

void getres(int t, int f, int p) {
  if (line[f][t]) f = t, res++;
  for (int i = fi[t]; i; i = ne[i]) {
    if (to[i] == fa[p][t]) continue;
    getres(to[i], f, p);
  }
}