#include <bits/stdc++.h>
using namespace std;
struct person {
  int frnd;
  int dis;
} relation[100005];
bool mark[100005];
int daya[100005], rating[100005];
int result, tmp, bgn, answer, next_friend, next_nex_friend;
void judge() { int i, j; }
int main() {
  int i, j;
  int n, m;
  int ii = 0, jj = 0, kk = 0;
  while (scanf("%d%d", &n, &m) != EOF) {
    result = 0;
    judge();
    memset(mark, 0, sizeof(mark));
    for (i = 1; i <= n; i++) {
      ii++;
      scanf("%d", &tmp);
      relation[i].frnd = tmp;
      relation[i].dis = 1;
      ii--;
    }
    for (i = 1; i <= m; i++) scanf("%d", &daya[i]);
    for (i = 1; i <= m; i++) scanf("%d", &rating[i]);
    for (i = 1; i <= m; i++) {
      answer = 0;
      bgn = (daya[i] + result - 1) % n + 1;
      if (mark[bgn] == 0) {
        answer++;
        mark[bgn] = 1;
      }
      next_friend = bgn;
      next_nex_friend = bgn;
      while (rating[i] > 0) {
        rating[i] -= relation[next_friend].dis;
        if (rating[i] <= 0) break;
        next_nex_friend = relation[next_friend].frnd;
        if (mark[next_nex_friend] == 0) {
          answer++;
          mark[next_nex_friend] = 1;
        }
        relation[next_friend].frnd = relation[next_nex_friend].frnd;
        relation[next_friend].dis += relation[next_nex_friend].dis;
        next_friend = next_nex_friend;
      }
      printf("%d\n", answer);
      result = answer;
    }
  }
  return 0;
}
