#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7, inf = -1e9;
int n, q, tot, ft[N], fa[N], ch[N], siz[N], dep[N], dfn[N], dft[N], ans[N],
    va[N << 3], vb[N << 3], vc[N << 3];
vector<int> v[N];
struct node {
  int u, t, w;
} e[N];
inline int read() {
  int num = 0;
  char g = getchar();
  while (g < 48 || 57 < g) g = getchar();
  while (47 < g && g < 58)
    num = (num << 1) + (num << 3) + g - 48, g = getchar();
  return num;
}
inline void dfs1(int u) {
  siz[u] = 1;
  for (int i = 0; i < v[u].size(); i++) {
    int x = v[u][i];
    dep[x] = dep[u] + 1, dfs1(x), siz[u] += siz[x];
    if (siz[ch[u]] <= siz[x]) ch[u] = x;
  }
}
inline void dfs2(int u) {
  if (!ft[u]) ft[u] = u;
  dfn[u] = ++tot, dft[tot] = u;
  if (ch[u]) ft[ch[u]] = ft[u], dfs2(ch[u]);
  for (int i = 0; i < v[u].size(); i++) {
    int x = v[u][i];
    if (ch[u] != x) dfs2(x);
  }
}
inline bool tmp(node a, node b) {
  if (a.t + dep[a.u] == b.t + dep[b.u]) return a.u < b.u;
  return a.t + dep[a.u] < b.t + dep[b.u];
}
inline void build(int l, int r, int t) {
  if (l == r) {
    va[t] = dep[dft[l]], vb[t] = inf, vc[t] = inf;
    return;
  }
  int d = (l + r) >> 1;
  build(l, d, t << 1), build(d + 1, r, t << 1 | 1);
  va[t] = max(va[t << 1], va[t << 1 | 1]), vb[t] = inf, vc[t] = inf;
}
inline void getvac(int l, int r, int t, int ql, int qr, int c) {
  if (l == ql && r == qr) {
    vb[t] = va[t] * 2 + c, vc[t] = c;
    return;
  }
  vc[t << 1] = max(vc[t << 1], vc[t]),
          vc[t << 1 | 1] = max(vc[t << 1 | 1], vc[t]);
  vb[t << 1] = max(vc[t << 1] + 2 * va[t << 1], vb[t << 1]),
          vb[t << 1 | 1] =
              max(vc[t << 1 | 1] + 2 * va[t << 1 | 1], vb[t << 1 | 1]);
  int d = (l + r) >> 1;
  if (ql <= d) getvac(l, d, t << 1, ql, min(qr, d), c);
  if (d + 1 <= qr) getvac(d + 1, r, t << 1 | 1, max(d + 1, ql), qr, c);
  vb[t] = max(vb[t << 1], vb[t << 1 | 1]);
}
inline int getmax(int l, int r, int t, int ql, int qr) {
  if (l == ql && r == qr) {
    return vb[t];
  }
  vc[t << 1] = max(vc[t << 1], vc[t]),
          vc[t << 1 | 1] = max(vc[t << 1 | 1], vc[t]);
  vb[t << 1] = max(vc[t << 1] + 2 * va[t << 1], vb[t << 1]),
          vb[t << 1 | 1] =
              max(vc[t << 1 | 1] + 2 * va[t << 1 | 1], vb[t << 1 | 1]);
  int d = (l + r) >> 1, w = inf;
  if (ql <= d) w = max(w, getmax(l, d, t << 1, ql, min(d, qr)));
  if (d + 1 <= qr) w = max(w, getmax(d + 1, r, t << 1 | 1, max(d + 1, ql), qr));
  return w;
}
int main() {
  n = read(), q = read(), n++;
  for (int i = 2; i <= n; i++) fa[i] = read() + 1, v[fa[i]].push_back(i);
  dfs1(1), dfs2(1);
  for (int i = 1; i <= q; i++) e[i].u = read() + 1, e[i].t = read(), e[i].w = i;
  sort(e + 1, e + q + 1, tmp), build(1, n, 1);
  for (int i = 1; i <= q; i++) {
    int u = e[i].u, t = e[i].t, z = u, s = 0, vac = 0;
    while (z > 0) {
      int v = getmax(1, n, 1, dfn[ft[z]], dfn[z]);
      if (v <= t + dep[u])
        z = fa[ft[z]];
      else {
        int l = dfn[ft[z]], r = dfn[z];
        while (l <= r) {
          int d = (l + r) >> 1;
          if (getmax(1, n, 1, d, dfn[z]) > t + dep[u])
            s = d, l = d + 1;
          else
            r = d - 1;
        }
        break;
      }
    }
    if (s == 0)
      vac = t + dep[u], ans[e[i].w] = t + dep[u] * 2;
    else
      vac = t + dep[u] - dep[dft[s]] * 2,
      ans[e[i].w] = t + (dep[u] - dep[dft[s]]) * 2;
    z = u;
    while (z > 0) {
      if (!(dfn[ft[z]] <= s && s <= dfn[z])) {
        getvac(1, n, 1, dfn[ft[z]], dfn[z], vac);
      } else {
        if (s == dfn[z]) break;
        getvac(1, n, 1, s + 1, dfn[z], vac);
        break;
      }
      z = fa[ft[z]];
    }
  }
  for (int i = 1; i <= q; i++) printf("%d ", ans[i]);
}
