#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:36777216")
using namespace std;
void solve();
int main() {
  ios::sync_with_stdio(0);
  solve();
  return 0;
}
const int KMaxN = 100000;
const int KSkipLen = 320;
struct Vertex {
  int next, skip;
  Vertex(int next = -1, int skip = -1) : next(next), skip(skip) {}
};
Vertex gr[KMaxN];
int N, M;
int V[KMaxN], B[KMaxN], R[KMaxN];
bool use[KMaxN];
int walk(int a, int cnt, int startA, int len) {
  if (a == -1) return 0;
  if (cnt <= 0) return 0;
  if (len > KSkipLen) exit(1);
  int add = use[a] ? 0 : 1;
  use[a] = true;
  if (len == KSkipLen) {
    gr[startA].skip = a;
    startA = a;
    len = 0;
  }
  if (gr[a].skip != -1 && cnt > KSkipLen) {
    return add + walk(gr[a].skip, cnt - KSkipLen, gr[a].skip, 0);
  } else {
    return add + walk(gr[a].next, cnt - 1, startA, len + 1);
  }
}
void solve() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    int next;
    cin >> next;
    gr[i].next = next - 1;
  }
  for (int i = 0; i < M; i++) cin >> V[i];
  for (int i = 0; i < M; i++) cin >> B[i];
  for (int i = 0; i < M; i++) {
    int resP = i == 0 ? 0 : R[i - 1];
    int a = (V[i] + resP - 1) % N;
    R[i] = walk(a, min(B[i], N), a, 0);
  }
  for (int i = 0; i < M; i++) {
    cout << R[i] << '\n';
  }
}
