#include <bits/stdc++.h>
using namespace std;
const int RLEN = 1 << 20 | 1;
inline char gc() {
  static char ibuf[RLEN], *ib, *ob;
  (ob == ib) && (ob = (ib = ibuf) + fread(ibuf, 1, RLEN, stdin));
  return (ob == ib) ? EOF : *ib++;
}
inline int read() {
  char ch = gc();
  int res = 0, f = 1;
  while (!isdigit(ch)) f ^= ch == '-', ch = gc();
  while (isdigit(ch)) res = (res + (res << 2) << 1) + (ch ^ 48), ch = gc();
  return f ? res : -res;
}
template <class tp>
inline void chemx(tp &a, tp b) {
  a < b ? a = b : 0;
}
template <class tp>
inline void chemn(tp &a, tp b) {
  a > b ? a = b : 0;
}
const int N = 1000005;
int n;
namespace Lct {
int son[N][2], fa[N], cov[N], val[N], c[N];
inline void init(int u, int f, int k) { fa[u] = f, val[u] = k, c[u] = -1e9; }
inline bool isrt(int u) {
  if (!fa[u]) return 1;
  return (son[fa[u]][0] != u && son[fa[u]][1] != u);
}
inline bool isrc(int u) { return son[fa[u]][1] == u; }
int stk[N], top;
inline void rotate(int v) {
  int u = fa[v], z = fa[u];
  int t = son[u][1] == v;
  if (!isrt(u)) son[z][son[z][1] == u] = v;
  fa[v] = z;
  son[u][t] = son[v][t ^ 1];
  fa[son[v][t ^ 1]] = u;
  fa[u] = v, son[v][t ^ 1] = u;
  c[v] = c[u];
}
inline void splay(int u) {
  while (!isrt(u)) {
    if (!isrt(fa[u])) isrc(u) == isrc(fa[u]) ? rotate(fa[u]) : rotate(u);
    rotate(u);
  }
}
inline int access(int u, int k) {
  int v;
  for (v = 0; u; v = u, u = fa[u]) {
    splay(u);
    if (c[u] + val[u] > k) break;
    c[son[u][1]] = c[u], son[u][1] = v;
  }
  if (v) c[v] = k - val[u];
  return val[u];
}
}  // namespace Lct
int m, fa[N], dep[N], ans[N];
struct ask {
  int u, t, id;
  friend inline bool operator<(const ask &a, const ask &b) {
    return a.t == b.t ? a.u < b.u : a.t < b.t;
  }
} p[N];
int main() {
  n = read() + 1, m = read();
  for (int i = 2; i <= n; i++) fa[i] = read() + 1, dep[i] = dep[fa[i]] + 1;
  for (int i = 1; i <= n; i++) Lct::init(i, fa[i], 2 * dep[i]);
  for (int i = 1; i <= m; i++) {
    int u = read() + 1, t = read();
    p[i].u = u, p[i].t = t + dep[u], p[i].id = i;
  }
  sort(p + 1, p + m + 1);
  for (int i = 1; i <= m; i++)
    ans[p[i].id] = dep[p[i].u] - Lct::access(p[i].u, p[i].t) + p[i].t;
  for (int i = 1; i <= m; i++) {
    cout << ans[i] << " ";
  }
}
