#include <bits/stdc++.h>
#define y1 aaaaaaaaaaaa
#pragma GCC optimize("O3")
#define gcd(a, b) ((!a || !b) ? (a || b) : __gcd(a, b))

using namespace std;

typedef long long ll;

mt19937 rnd(1);

const int N = 2e3 + 7;

vector <int> g[N];
bool die[N];

int sz[N];

void build_sz(int v, int pr)
{
  sz[v] = 1;
  for (int to : g[v])
  {
    if (to != pr && !die[to])
    {
      build_sz(to, v);
      sz[v] += sz[to];
    }
  }
}

int find_centroid(int v, int pr, int need)
{
  for (int to : g[v])
  {
    if (to != pr && !die[to] && sz[to] > need)
    {
      return find_centroid(to, v, need);
    }
  }
  return v;
}

bitset <N> ans[N];

const int LG = 12;

int par[N][LG];
int f[N];
bitset <N> path[N][LG];
bitset <N> ot[N][LG];
int tin[N], tout[N];

int tt = 0;

void get_verts(int v, int pr, vector <int> &ret)
{
  ret.push_back(v);
  tin[v] = tt++;
  for (int to : g[v])
  {
    if (to != pr && !die[to])
    {
      get_verts(to, v, ret);
    }
  }
  tout[v] = tt++;
}

void build(int v, int dep)
{
  build_sz(v, -1);
  int x = find_centroid(v, -1, sz[v] / 2);
  vector <int> was = {x};
  f[x] = dep;
  for (int to : g[x])
  {
    if (!die[to])
    {
      vector <int> verts;
      get_verts(to, x, verts);
      for (int i = 0; i < (int) verts.size(); i++)
      {
        for (int j = 0; j < (int) verts.size(); j++)
        {
          if (i != j && tin[verts[i]] <= tin[verts[j]] && tout[verts[j]] <= tout[verts[i]])
          {
            path[verts[i]][dep][verts[j]] = path[verts[j]][dep][verts[i]] = 1;
          }
        }
      }
      for (int x : was)
      {
        for (int y : verts)
        {
          ot[x][dep][y] = ot[y][dep][x] = 1;
        }
      }
      for (int kek : verts) was.push_back(kek);
    }
  }
  for (int kek : was)
  {
    path[kek][dep][x] = path[x][dep][kek] = 1;
    par[kek][dep] = x;
  }
  {
    die[x] = true;
    for (int to : g[x])
    {
      if (!die[to])
      {
        build(to, dep + 1);
      }
    }
  }
}

vector <pair <int, int> > e;

bitset <N> kok;

void flex(int a, int b)
{
  for (int i = 0; i <= f[a] && i <= f[b]; i++)
  {
    if (par[a][i] == par[b][i])
    {
      if (a == par[a][i] || b == par[b][i])
      {
        if (a == par[a][i])
        {
          kok = (path[b][i] | ot[b][i]) & ans[a] & ~ans[b];
        }
        else
        {
          kok = (path[a][i] | ot[a][i]) & ans[a] & ~ans[b];
        }
      }
      else
      {
        if (ot[a][i][b])
        {
          kok = (path[a][i] | path[b][i]) & ans[a] & ~ans[b];
        }
        else if (path[a][i][b])
        {
          kok = ot[a][i] & ans[a] & ~ans[b];
        }
        else
        {
          continue;
        }
      }
      vector <int> bits;
#ifdef ONPC
      for (int i = 0; i < N; i++) if (kok[i]) bits.push_back(i);
#else
      for (int i = kok._Find_first(); i < N; i = kok._Find_next(i))
      {
        bits.push_back(i);
      }
#endif
      for (int v : bits)
      {
        ans[b][v] = ans[v][b] = 1;
        e.emplace_back(v, b);
      }
    }
  }
}

void add_edge(int a, int b)
{
  flex(a, b);
  flex(b, a);
}

vector <int> pth;

/*
void zhfs(int v, int pr)
{
  pth.push_back(v);
  for (int i = 0; i < (int) pth.size(); i++)
  {
    for (int j = 0; j < (int) pth.size(); j++)
    {
      for (int k = 0; k < (int) pth.size(); k++)
      {
        if (i == j || j == k || i == k) continue;
        if (ans[pth[i]][pth[j]] && ans[pth[j]][pth[k]] && !ans[pth[i]][pth[k]])
        {
          cout << pth[i] << ' ' << pth[j] << endl;
          cout << pth[j] << ' ' << pth[k] << endl;
          cout << pth[i] << ' ' << pth[k] << endl;
          assert(0);
        }
      }
    }
  }
  for (int to : g[v])
  {
    if (to != pr)
    {
      zhfs(to, v);
    }
  }
  pth.pop_back();
}
 */

void solve()
{
  int n, m;
  cin >> n >> m;
  for (int i = 1; i < n; i++)
  {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 0; i < n; i++) ans[i][i] = 1;
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    a--, b--;
    ans[a][b] = ans[b][a] = 1;
    e.emplace_back(a, b);
  }
  build(0, 0);
  for (int i = 0; i < (int) e.size(); i++)
  {
    add_edge(e[i].first, e[i].second);
  }
  cout << e.size() << endl;
}

int main()
{
#ifdef ONPC
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  solve();
}


Measured memory_bytes: 31468