#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};
long long bigmod(long long a, long long b, long long c) {
  if (b == 0) return 1 % c;
  long long x = bigmod(a, b / 2, c);
  x = (x * x) % c;
  if (b % 2 == 1) x = (x * a) % c;
  return x;
}
long long mod_inverse(long long a, long long mod) {
  return bigmod(a, mod - 2, mod);
}
const int M = 100005;
int st[M], ed[M], cnt, n, m, lvl[M];
vector<int> adj[M];
pair<long long, long long> sum[M * 4], summ[M * 4];
void update(int l, int r, int k, int L, int val) {
  if (l == r) {
    sum[k] = {val, l};
    return;
  }
  int mid = (l + r) / 2;
  if (mid >= L) {
    update(l, mid, k * 2, L, val);
  } else {
    update(mid + 1, r, k * 2 + 1, L, val);
  }
  sum[k] = max(sum[k * 2], sum[k * 2 + 1]);
}
pair<long long, long long> query(int l, int r, int k, int L, int R) {
  if (l > R || r < L) return {0, 0};
  if (l >= L && r <= R) return sum[k];
  int mid = (l + r) / 2;
  return max(query(l, mid, k * 2, L, R), query(mid + 1, r, k * 2 + 1, L, R));
}
void update2(int l, int r, int k, int L, int val) {
  if (l == r) {
    summ[k] = {val, l};
    return;
  }
  int mid = (l + r) / 2;
  if (mid >= L) {
    update2(l, mid, k * 2, L, val);
  } else {
    update2(mid + 1, r, k * 2 + 1, L, val);
  }
  summ[k] = min(summ[k * 2], summ[k * 2 + 1]);
}
pair<long long, long long> query2(int l, int r, int k, int L, int R) {
  if (l > R || r < L) return {1e6, 0};
  if (l >= L && r <= R) return summ[k];
  int mid = (l + r) / 2;
  return min(query2(l, mid, k * 2, L, R), query2(mid + 1, r, k * 2 + 1, L, R));
}
int par[M], sp[M][20], a[M];
void dfs(int p, int x, int lv) {
  st[x] = ++cnt;
  a[cnt] = x;
  lvl[x] = lv;
  par[x] = p;
  update(1, n, 1, x, cnt);
  update2(1, n, 1, x, cnt);
  for (auto y : adj[x]) {
    if (p == y) continue;
    dfs(x, y, lv + 1);
  }
  ed[x] = cnt;
}
void build(int n) {
  for (int i = 1; i <= n; i++) {
    sp[i][0] = par[i];
  }
  for (int i = 1; (1 << i) <= n; i++) {
    for (int j = 1; j <= n; j++) {
      sp[j][i] = sp[sp[j][i - 1]][i - 1];
    }
  }
}
int lca_of(int u, int v) {
  if (lvl[u] > lvl[v]) swap(u, v);
  for (int i = 17; i >= 0; i--) {
    if (!sp[v][i]) continue;
    if (lvl[sp[v][i]] >= lvl[u]) {
      v = sp[v][i];
    }
  }
  if (u == v) return u;
  for (int i = 17; i >= 0; i--) {
    if (sp[u][i] == sp[v][i]) continue;
    u = sp[u][i];
    v = sp[v][i];
  }
  return par[u];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 2; i <= n; i++) {
    int u;
    cin >> u;
    adj[u].push_back(i);
    adj[i].push_back(u);
  }
  dfs(0, 1, 0);
  build(n);
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    pair<long long, long long> fmn, smn, fmx, smx;
    fmx = query(1, n, 1, l, r);
    fmn = query2(1, n, 1, l, r);
    update(1, n, 1, fmx.second, 0);
    update2(1, n, 1, fmn.second, 1e6);
    smx = query(1, n, 1, l, r);
    smn = query2(1, n, 1, l, r);
    update(1, n, 1, fmx.second, fmx.first);
    update2(1, n, 1, fmn.second, fmn.first);
    pair<long long, long long> p, q;
    p = {fmn.first, smx.first};
    q = {smn.first, fmx.first};
    int x, y, u, v;
    u = a[p.first], v = a[p.second];
    x = lca_of(u, v);
    u = a[q.first], v = a[q.second];
    y = lca_of(u, v);
    if (lvl[x] > lvl[y])
      cout << fmx.second << " " << lvl[x] << "\n";
    else
      cout << fmn.second << " " << lvl[y] << "\n";
  }
  return 0;
}
