#include <bits/stdc++.h>
using namespace std;
const int MN = 1000 * 100 + 50;
struct friends {
  int d, nxt;
  bool used;
};
int n, m, g[MN], b[MN], v[MN], ans[MN];
friends dp[MN];
int solve(int ai, int bi) {
  if (!bi) return 0;
  if (dp[ai].used) {
    if (ai == dp[ai].nxt) return 0;
    if (bi > dp[ai].d) {
      int tmp = solve(dp[ai].nxt, bi - dp[ai].d);
      dp[ai].d += dp[dp[ai].nxt].d;
      dp[ai].nxt = dp[dp[ai].nxt].nxt;
      return tmp;
    }
    return 0;
  }
  dp[ai].used = true;
  int tmp = 1 + solve(g[ai], bi - 1);
  dp[ai].d = dp[g[ai]].d + 1;
  dp[ai].nxt = dp[g[ai]].nxt;
  return tmp;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &g[i]);
    dp[i].nxt = i;
    dp[i].used = false;
    dp[i].d = 0;
  }
  for (int i = 1; i <= m; i++) scanf("%d", &v[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &b[i]);
    int ai = (v[i] + ans[i - 1] - 1) % n + 1;
    ans[i] = solve(ai, b[i]);
    printf("%d ", ans[i]);
  }
  return 0;
}
