#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

const int N = 2048;
bitset<N> e[N], antie[N];
bitset<N> pr[N], anc[N];
bitset<N> antipr[N], antianc[N];
vvi g(N);

const int D = 12;
int lc[2005][D];
vi in, out;
int TT = 0;

const int BB = 1 << 16;
int small[BB];
int smallest_bit(unsigned int v) {
  if (!v) return 1e9;
  unsigned int v1 = v & (BB - 1);
  if (v1) return small[v1];
  else return 16 + small[(v ^ v1) >> 16];
}
int get_first(int l, int r, const bitset<N>& a) {  // [l, r)
  int ans = r;
  if (l >= r) return ans;
  const int B = 32;
  const unsigned int* c = reinterpret_cast<const unsigned int*>(&a);
  /*if (l / B == r / B) {
    ans = min(ans, l + smallest_bit((c[l / B] & ((1 << (r % B)) - 1)) >> (l % B)));
    return ans;
  }*/
  //ans = min(ans, l + smallest_bit(c[l / B]));
  //ans = min(ans, l + smallest_bit(c[l / B] >> (l % B)));
  for (int i = l / B; i < r / B; ++i) if (c[i]) {
    return i * B + smallest_bit(c[i]);
  }
  /*if (r % B != 0) {
    ans = min(ans, r - 1 - (B - 1) + smallest_bit((c[r / B] << (B - r % B))));
  }*/
  return ans;
}

void dfs(int v, int p) {
  lc[v][0] = p;
  pr[v] = pr[p];
  if (v != p) pr[v].set(p);
  antipr[v] = pr[v];
  antipr[v].flip();
  for (int i = 1; i < D; ++i) {
    lc[v][i] = lc[lc[v][i - 1]][i - 1];
  }
  in[v] = ++TT;
  for (int i = 0; i < (int)g[v].size(); ++i) if (g[v][i] != p) {
    dfs(g[v][i], v);
    anc[v] |= anc[g[v][i]];
  }
  anc[v].set(v);
  antianc[v] = anc[v];
  antianc[v].flip();
  out[v] = ++TT;
}

int lca(int u, int v) {
  if (in[u] > in[v]) swap(u, v);
  if (out[u] >= out[v]) return u;
  for (int h = D-1; h >= 0; --h) {
    if (out[lc[u][h]] < out[v]) {
      u = lc[u][h];
    }
  }
  return lc[u][0];
}

int lca1(int u, int v) {
  for (int h = D-1; h >= 0; --h) {
    if (out[lc[u][h]] < out[v]) {
      u = lc[u][h];
    }
  }
  return u;
}

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  for (int i = 2; i < BB; i += 2) small[i] = 1 + small[i / 2];
  int n, m;
  cin >> n >> m;
  g.resize(n);
  in.resize(n);
  out.resize(n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0, 0);
  vii todo;
  for (int i = 0; i < n; ++i) antie[i].set();
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    e[a].set(b);
    e[b].set(a);
    antie[a].reset(b);
    antie[b].reset(a);
    todo.emplace_back(a, b);
  }
  bitset<N> tr, cand; 
  int ans = todo.size();
  while (!todo.empty()) {
    int a0 = todo.back().first, b0 = todo.back().second;
    todo.pop_back();
    for (int t = 0; t < 2; ++t) {
      swap(a0, b0);
      cand = e[a0] & antie[b0];
      int a = a0, b = b0;
      cand.reset(a);
      cand.reset(b);
      int c = lca(a, b);
      tr = (pr[a] | pr[b]) & antipr[c];
      if (c != a) tr |= anc[a];
      if (c != b) tr |= anc[b];
      if (c == b) swap(a, b);
      if (c == a) {
        int a1 = lca1(b, a);
        tr |= antianc[a1];
      }
      tr &= cand;
      int p = 0;
      while (true) {
        int i = get_first(p, N, tr);
        if (i >= N) break;
        p = i / 32 * 32;
        tr.reset(i);
//        assert(e[a0][i]);
//        assert(i < n);
//        cerr << b0 << ' ' << i << endl;
        ++ans;
        e[b0].set(i);
        e[i].set(b0);
        antie[b0].reset(i);
        antie[i].reset(b0);
        todo.emplace_back(b0, i);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 22248