#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
struct Edge {
  int to, nt;
} e[N << 1];
struct Que {
  int x, t, id;
} q[N];
int top[N], dfn[N], fa[N], son[N], sz[N], Index;
int n, m, dep[N], sd[N], cnt, ft[N], Ans[N];
int tag[N << 2], mx[N << 2], dps[N << 2];
int read() {
  int x = 0, o = 1;
  char ch = getchar();
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') o = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
bool cmp(Que x, Que y) {
  if (dep[x.x] + x.t == dep[y.x] + y.t) return x.x < y.x;
  return dep[x.x] + x.t < dep[y.x] + y.t;
}
void Add(int u, int v) {
  e[++cnt] = (Edge){v, ft[u]};
  ft[u] = cnt;
  e[++cnt] = (Edge){u, ft[v]};
  ft[v] = cnt;
}
void dfs1(int u, int Fa) {
  sz[u] = 1, dep[u] = dep[Fa] + 1;
  for (int i = ft[u]; i; i = e[i].nt) {
    int v = e[i].to;
    if (v == Fa) continue;
    dfs1(v, u), fa[v] = u;
    if (sz[v] > sz[son[u]]) son[u] = v;
    sz[u] += sz[v];
  }
}
void dfs2(int u, int fa) {
  dfn[u] = ++Index, sd[Index] = dep[u];
  if (son[u]) top[son[u]] = top[u], dfs2(son[u], u);
  for (int i = ft[u]; i; i = e[i].nt) {
    int v = e[i].to;
    if (v == fa || v == son[u]) continue;
    top[v] = v, dfs2(v, u);
  }
}
void pushup(int x) { mx[x] = max(mx[x << 1], mx[x << 1 | 1]); }
void put(int x, int y) { mx[x] = dps[x] + y, tag[x] = y; }
void pushdown(int x) {
  if (tag[x] != tag[0])
    put(x << 1, tag[x]), put(x << 1 | 1, tag[x]), tag[x] = tag[0];
}
void Build(int x, int l, int r) {
  if (l == r) {
    dps[x] = sd[l] << 1;
    return;
  }
  Build(x << 1, l, ((l + r) >> 1)), Build(x << 1 | 1, ((l + r) >> 1) + 1, r);
  dps[x] = max(dps[x << 1], dps[x << 1 | 1]);
}
int Q(int x, int l, int r, int L, int R) {
  if (L <= l && r <= R) return mx[x];
  pushdown(x);
  int maxx = -2e9;
  if (L <= ((l + r) >> 1)) maxx = max(maxx, Q(x << 1, l, ((l + r) >> 1), L, R));
  if (R > ((l + r) >> 1))
    maxx = max(maxx, Q(x << 1 | 1, ((l + r) >> 1) + 1, r, L, R));
  return maxx;
}
void Update(int x, int l, int r, int L, int R, int val) {
  if (L <= l && r <= R) {
    put(x, val);
    return;
  }
  pushdown(x);
  if (L <= ((l + r) >> 1)) Update(x << 1, l, ((l + r) >> 1), L, R, val);
  if (R > ((l + r) >> 1)) Update(x << 1 | 1, ((l + r) >> 1) + 1, r, L, R, val);
  pushup(x);
}
int solve(int x, int t) {
  int p = dfn[x] + 1, Ans = 0, xx = x;
  for (; x; p = dfn[top[x]], x = fa[top[x]]) {
    int l = dfn[top[x]], r = dfn[x];
    if (Q(1, 1, n, l, r) <= t + dep[xx]) continue;
    while (l <= r) {
      int mx = Q(1, 1, n, ((l + r) >> 1), r);
      if (mx > t + dep[xx])
        l = ((l + r) >> 1) + 1;
      else
        p = ((l + r) >> 1), r = ((l + r) >> 1) - 1;
    }
    break;
  }
  if (p == dfn[xx] + 1)
    Ans = t;
  else if (p == 1)
    Ans = t + (dep[xx] - 1) * 2;
  else
    Ans = t + (dep[xx] - sd[p] + 1) * 2;
  x = xx;
  for (; x && dfn[top[x]] > p; x = fa[top[x]])
    Update(1, 1, n, dfn[top[x]], dfn[x], Ans - dep[xx]);
  if (p) Update(1, 1, n, p, dfn[x], Ans - dep[xx]);
  return Ans;
}
int main() {
  memset(tag, -31, sizeof(tag));
  memset(mx, -31, sizeof(mx));
  n = read() + 1, m = read();
  for (int i = 2; i <= n; i++) Add(i, read() + 1);
  for (int i = 1; i <= m; i++) q[i] = (Que){read() + 1, read(), i};
  dfs1(1, 0), top[1] = 1, dfs2(1, 0);
  sd[1] = -1e9, Build(1, 1, n), sd[1] = 1;
  sort(q + 1, q + 1 + m, cmp);
  for (int i = 1; i <= m; i++) Ans[q[i].id] = solve(q[i].x, q[i].t);
  for (int i = 1; i <= m; i++) printf("%d ", Ans[i]);
  puts("");
  return 0;
}
