#include <bits/stdc++.h>
using namespace std;
int urm[100010];
int dist[100010];
bool alive[100010], active[100010];
bool used[100010];
int v[100010], b[100010];
void calc(int x) {
  if (active[x] || !alive[x]) {
    urm[x] = 0;
    return;
  }
  if (used[urm[x]]) {
    active[x] = 1;
    calc(urm[x]);
    active[x] = 0;
    dist[x] += dist[urm[x]];
    urm[x] = urm[urm[x]];
    if (!urm[x]) alive[x] = 0;
  }
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  used[0] = 1;
  for (int i(1); i <= n; i++) {
    cin >> urm[i];
    dist[i] = 1;
    alive[i] = 1;
  }
  for (int i(1); i <= m; i++) cin >> v[i];
  for (int i(1); i <= m; i++) cin >> b[i];
  int last(0);
  for (int i(1); i <= m; i++) {
    int t = b[i], nod = (v[i] + last - 1) % n + 1, ans(0);
    while (t > 0 && nod) {
      if (!used[nod]) used[nod] = 1, ans++;
      calc(nod);
      t -= dist[nod];
      nod = urm[nod];
    }
    cout << ans << '\n';
    last = ans;
  }
  return 0;
}
