#include <bits/stdc++.h>
#include <iostream>
#include <istream>
using namespace std;

const int MAXN = 1e6 + 5;
const int LOG = 20;

vector<int> adj[MAXN];
vector<int> euler;
int first[MAXN], depth[MAXN];
int st_rmq[LOG][MAXN * 2];
int log_table[MAXN * 2];
int st_lca[LOG][MAXN];

struct State {
    int u, parent;
    vector<int>::iterator it;
};

void iterative_dfs() {
    stack<State> st;
    st.push({1, -1, adj[1].begin()});
    first[1] = euler.size();
    euler.push_back(1);
    depth[1] = 0;

    while (!st.empty()) {
        auto& s = st.top();
        if (s.it == adj[s.u].end()) {
            st.pop();
            if (s.parent != -1) {
                euler.push_back(s.parent);
            }
        } else {
            int v = *s.it;
            s.it++;
            if (v == s.parent) continue;
            first[v] = euler.size();
            euler.push_back(v);
            depth[v] = depth[s.u] + 1;
            st.push({v, s.u, adj[v].begin()});
        }
    }
}

void build_rmq() {
    int m = euler.size();
    log_table[1] = 0;
    for (int i = 2; i <= m; ++i)
        log_table[i] = log_table[i/2] + 1;
    for (int i = 0; i < m; ++i)
        st_rmq[0][i] = i;
    for (int k = 1; (1 << k) <= m; ++k) {
        for (int i = 0; i + (1 << k) <= m; ++i) {
            int a = st_rmq[k-1][i];
            int b = st_rmq[k-1][i + (1 << (k-1))];
            st_rmq[k][i] = (depth[euler[a]] < depth[euler[b]] ? a : b);
        }
    }
}

int lca(int u, int v) {
    int l = first[u], r = first[v];
    if (l > r) swap(l, r);
    int k = log_table[r - l + 1];
    int a = st_rmq[k][l];
    int b = st_rmq[k][r - (1 << k) + 1];
    return euler[depth[euler[a]] < depth[euler[b]] ? a : b];
}

void build_lca_st(int n) {
    for (int i = 1; i <= n; ++i)
        st_lca[0][i] = i;
    for (int k = 1; (1 << k) <= n; ++k) {
        for (int i = 1; i + (1 << k) - 1 <= n; ++i) {
            int a = st_lca[k-1][i];
            int b = st_lca[k-1][i + (1 << (k-1))];
            st_lca[k][i] = lca(a, b);
        }
    }
}

int query(int l, int r) {
    if (l == r) return l;
    int len = r - l + 1;
    int k = log_table[len];
    int a = st_lca[k][l];
    int b = st_lca[k][r - (1 << k) + 1];
    return lca(a, b);
}

int main() {
    iostream::sync_with_stdio(false),cin.tie(nullptr);
    int n, q;
    cin>>n>>q;
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    iterative_dfs();
    build_rmq();
    build_lca_st(n);
    while (q--) {
        int l, r;
        cin>>l>>r;
        cout<<query(l, r)<<'\n';
    }
    return 0;
}