#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 2;
int seg[4 * maxn], T, sz[maxn], h[maxn], st[maxn], root[maxn], up[maxn], n,
    par[maxn], dp[maxn];
vector<int> adj[maxn], ch[maxn], C;
bool lazy[4 * maxn];
bitset<maxn> mark, c;
bool cmp(int a, int b) { return sz[a] > sz[b]; }
void relax(int id, int L, int mid, int R) {
  bool x = lazy[id];
  if (!x) return;
  lazy[id] = 0;
  seg[2 * id + 0] = mid - L - seg[2 * id + 0];
  seg[2 * id + 1] = R - mid - seg[2 * id + 1];
  lazy[2 * id + 0] ^= 1;
  lazy[2 * id + 1] ^= 1;
}
void add(int id, int L, int R, int l, int r) {
  if (R <= l || r <= L || r <= l) {
    return;
  }
  if (L >= l && R <= r) {
    seg[id] = R - L - seg[id];
    lazy[id] ^= 1;
    return;
  }
  int mid = (L + R) / 2;
  relax(id, L, mid, R);
  add(2 * id + 0, L, mid, l, r);
  add(2 * id + 1, mid, R, l, r);
  seg[id] = seg[2 * id + 0] + seg[2 * id + 1];
}
int get(int id, int L, int R, int l, int r) {
  if (R <= l || r <= L || r <= l) {
    return 0;
  }
  if (L >= l && R <= r) {
    return seg[id];
  }
  int mid = (L + R) / 2;
  relax(id, L, mid, R);
  return get(2 * id + 0, L, mid, l, r) + get(2 * id + 1, mid, R, l, r);
}
void getcycle(int v, int p = -1) {
  mark[v] = 1;
  dp[v] = h[v];
  for (auto u : adj[v]) {
    if (!mark[u]) {
      h[u] = h[v] + 1;
      getcycle(u, v);
      dp[v] = min(dp[v], dp[u]);
    } else if (u != p && !c[u]) {
      C.push_back(u);
      c[u] = 1;
      dp[v] = h[u];
    }
  }
  if (dp[v] < h[v]) {
    C.push_back(v);
    c[v] = 1;
  }
}
void getsz(int v, int r, int p = -1) {
  sz[v] = 1;
  root[v] = r;
  for (auto u : adj[v]) {
    if (u != p && !c[u]) {
      h[u] = h[v] + 1;
      ch[v].push_back(u);
      par[u] = v;
      getsz(u, r, v);
      sz[v] += sz[u];
    }
  }
}
void dfs(int v) {
  st[v] = T++;
  bool heavy = 1;
  sort(ch[v].begin(), ch[v].end(), cmp);
  for (auto u : ch[v]) {
    if (heavy) {
      up[u] = up[v];
      heavy = 0;
    } else
      up[u] = u;
    dfs(u);
  }
}
void add(int v) {
  while (h[v]) {
    add(1, 0, n, st[up[v]], st[v] + 1);
    v = par[up[v]];
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int v, u;
    cin >> v >> u;
    v--;
    u--;
    adj[v].push_back(u);
    adj[u].push_back(v);
  }
  getcycle(0);
  for (int i = 0; i < C.size(); i++) {
    st[C[i]] = i;
    h[C[i]] = 0;
  }
  T = C.size();
  for (int i = 0; i < C.size(); i++) {
    root[C[i]] = C[i];
    for (auto u : adj[C[i]]) {
      if (!c[u]) {
        par[u] = C[i];
        h[u] = 1;
        getsz(u, C[i]);
      }
    }
  }
  for (int i = 0; i < C.size(); i++) {
    for (auto u : adj[C[i]]) {
      if (!c[u]) {
        up[u] = u;
        dfs(u);
      }
    }
  }
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    v--;
    u--;
    add(v);
    add(u);
    v = root[v];
    u = root[u];
    int V = v;
    if (st[v] > st[u]) swap(v, u);
    if (2 * (st[u] - st[v]) < C.size()) {
      add(1, 0, n, st[v], st[u]);
    } else if (2 * (st[u] - st[v]) > C.size()) {
      add(1, 0, n, 0, st[v]);
      add(1, 0, n, st[u], C.size());
    } else {
      if (v == V) {
        if (C[st[v] + 1] < C[(st[v] - 1 + C.size()) % C.size()]) {
          add(1, 0, n, st[v], st[u]);
        } else {
          add(1, 0, n, 0, st[v]);
          add(1, 0, n, st[u], C.size());
        }
      } else {
        if (C[st[u] - 1] < C[(st[u] + 1) % C.size()]) {
          add(1, 0, n, st[v], st[u]);
        } else {
          add(1, 0, n, 0, st[v]);
          add(1, 0, n, st[u], C.size());
        }
      }
    }
    cout << n - get(1, 0, n, 0, n) +
                (bool)(get(1, 0, n, 0, C.size()) == C.size())
         << '\n';
  }
}
