#include <bits/stdc++.h>
int const N = 100100;
int len[N];
int g[N], next[N];
int find(int v) {
  if (next[v] != v) {
    int root = find(next[v]);
    len[v] += len[next[v]];
    next[v] = root;
  }
  return next[v];
}
int v[N], res[N];
bool did[N];
int calc(int a, int b) {
  int ret = 0;
  find(a);
  b -= len[a];
  a = next[a];
  while (b > 0 && !did[a]) {
    ++ret;
    did[a] = true;
    next[a] = find(g[a]);
    len[a] = 1 + len[g[a]];
    b -= len[a];
    a = find(g[a]);
  }
  return ret;
}
void solve() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    next[i] = i;
    len[i] = 0;
    scanf("%d", g + i);
    --g[i];
  }
  for (int i = 1; i <= m; ++i) {
    scanf("%d", v + i);
  }
  for (int i = 1; i <= m; ++i) {
    int b;
    scanf("%d", &b);
    int a = (v[i] + res[i - 1] - 1) % n;
    res[i] = calc(a, b);
  }
  for (int i = 1; i <= m; ++i) {
    printf("%d\n", res[i]);
  }
}
int main() { solve(); }
