#include <bits/stdc++.h>
using namespace std;
class sgt {
 public:
  int val[800010], sum[800010];
  void modify(int p, int l, int r, int ml, int mr, int v) {
    if (ml > mr) return;
    if (ml <= l && r <= mr) {
      val[p] += v;
      if (val[p])
        sum[p] = r - l + 1;
      else if (l == r)
        sum[p] = 0;
      else
        sum[p] = sum[(p << 1)] + sum[((p << 1) | 1)];
      return;
    }
    int mid = (l + r) >> 1;
    if (ml <= mid) modify((p << 1), l, mid, ml, mr, v);
    if (mr > mid) modify(((p << 1) | 1), mid + 1, r, ml, mr, v);
    if (val[p])
      sum[p] = r - l + 1;
    else
      sum[p] = sum[(p << 1)] + sum[((p << 1) | 1)];
  }
} T;
int n, q;
map<pair<int, int>, int> mp;
vector<int> v[200010];
int fa[200010][19], l[200010], r[200010], tim = 0, dep[200010];
void dfs(int np, int fath) {
  fa[np][0] = fath;
  l[np] = ++tim;
  dep[np] = dep[fath] + 1;
  for (int x : v[np]) {
    if (x == fath) continue;
    dfs(x, np);
  }
  r[np] = tim;
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1, ti, tj; i < n; i++) {
    scanf("%d%d", &ti, &tj);
    v[ti].push_back(tj);
    v[tj].push_back(ti);
  }
  dfs(1, 0);
  for (int j = 1; j < 19; j++)
    for (int i = 1; i <= n; i++) fa[i][j] = fa[fa[i][j - 1]][j - 1];
  while (q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (l[x] > l[y]) swap(x, y);
    int c = 0;
    if (mp.find(make_pair(x, y)) == mp.end())
      mp[make_pair(x, y)] = 1, c = 1;
    else
      mp.erase(make_pair(x, y)), c = -1;
    if (r[x] >= r[y]) {
      int t = y;
      for (int i = 18; i >= 0; i--)
        if (dep[fa[t][i]] > dep[x]) t = fa[t][i];
      T.modify(1, 1, n, l[t], l[y] - 1, c);
      T.modify(1, 1, n, r[y] + 1, r[t], c);
    } else {
      T.modify(1, 1, n, 1, l[x] - 1, c);
      T.modify(1, 1, n, r[x] + 1, l[y] - 1, c);
      T.modify(1, 1, n, r[y] + 1, n, c);
    }
    printf("%d\n", n - T.sum[1]);
  }
  return 0;
}
