#include <bits/stdc++.h>
int inp() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  int sum = 0;
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum;
}
int idx = 0;
int head[200010], nxt[400010], end[400010];
int cou = 0;
void link(int a, int b) {
  nxt[++cou] = head[a];
  head[a] = cou;
  end[cou] = b;
}
int fa[200010][23], depth[200010], dfn[200010], size[200010];
std::unordered_map<int, bool> used[200010];
void dfs(int cur, int last) {
  depth[cur] = depth[last] + 1;
  fa[cur][0] = last;
  for (int i = 1; i <= 20; i++) fa[cur][i] = fa[fa[cur][i - 1]][i - 1];
  dfn[cur] = ++idx;
  size[cur] = 1;
  for (int x = head[cur]; x != -1; x = nxt[x]) {
    if (end[x] != last) {
      dfs(end[x], cur);
      size[cur] += size[end[x]];
    }
  }
}
struct SEG_Tree {
  struct SEG {
    int l;
    int r;
    int sum;
    int lazy;
  } t[2000000];
  void build(int cur, int l, int r) {
    t[cur].l = l;
    t[cur].r = r;
    if (l == r) return;
    int mid = (l + r) >> 1;
    build(((cur) << 1), l, mid);
    build(((cur) << 1 | 1), mid + 1, r);
  }
  void push_up(int cur) {
    t[cur].sum = t[cur].lazy ? (t[cur].r - t[cur].l + 1)
                             : t[((cur) << 1)].sum + t[((cur) << 1 | 1)].sum;
  }
  void modify(int cur, int l, int r, int c) {
    if (t[cur].l > r || t[cur].r < l || l > r) return;
    if (t[cur].l >= l && t[cur].r <= r) {
      t[cur].lazy += c;
      push_up(cur);
      return;
    }
    modify(((cur) << 1), l, r, c);
    modify(((cur) << 1 | 1), l, r, c);
    push_up(cur);
  }
  int query(int cur, int l, int r) {
    if (t[cur].l > r || t[cur].r < l) return 0;
    if (t[cur].l >= l && t[cur].r <= r) return t[cur].sum;
    return query(((cur) << 1), l, r) + query(((cur) << 1 | 1), l, r);
  }
} t;
int main() {
  memset(head, -1, sizeof(head));
  int n = inp();
  int q = inp();
  for (int i = 1; i < n; i++) {
    int u = inp();
    int v = inp();
    link(u, v);
    link(v, u);
  }
  dfs(1, 0);
  t.build(1, 1, n);
  while (q--) {
    int u = inp();
    int v = inp();
    if (dfn[u] > dfn[v]) std::swap(u, v);
    int last = used[u][v];
    used[u][v] ^= 1;
    int w = used[u][v] - last;
    if (dfn[u] < dfn[v] && dfn[v] < dfn[u] + size[u]) {
      int delta = depth[v] - depth[u] - 1;
      int m = v;
      for (int i = 0; i <= 20; i++)
        if (delta & (1 << i)) m = fa[m][i];
      t.modify(1, dfn[m], dfn[v] - 1, w);
      t.modify(1, dfn[v] + size[v], dfn[m] + size[m] - 1, w);
    } else {
      t.modify(1, 1, dfn[u] - 1, w);
      t.modify(1, dfn[u] + size[u], dfn[v] - 1, w);
      t.modify(1, dfn[v] + size[v], n, w);
    }
    printf("%d\n", n - t.query(1, 1, n));
  }
}
