#include <bits/stdc++.h>
long n, m;
long next[200005] = {0}, next_[200005] = {0}, d[200005] = {0};
long v[200005] = {0}, b[200005] = {0}, res[200005] = {0}, A[200005] = {0},
     hush[200005] = {0};
long find(long now) {
  if (now == next_[now]) return (now);
  long fmp = next_[now];
  next_[now] = find(next_[now]);
  d[now] += d[fmp];
  return (next_[now]);
}
int main() {
  long i, j, k, s, go;
  scanf("%ld%ld", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%ld", &next[i]);
    next_[i] = i;
    d[i] = 0;
  }
  for (i = 1; i <= m; i++) scanf("%ld", &v[i]);
  for (i = 1; i <= m; i++) {
    scanf("%ld", &b[i]);
    if (i == 4) i = 4;
    A[i] = (v[i] + res[i - 1] - 1) % n + 1;
    k = A[i];
    s = b[i];
    go = find(k);
    while (s && !hush[go]) {
      s -= d[k] + 1;
      if (s < 0) break;
      res[i]++;
      k = go;
      go = find(next[k]);
      if (go == k)
        hush[k] = 1;
      else {
        next_[k] = go;
        d[k] = d[next[k]] + 1;
      }
      k = next[k];
      go = find(k);
    }
  }
  for (i = 1; i <= m; i++) printf("%ld\n", res[i]);
  return (0);
}
