#include <bits/stdc++.h>
using namespace std;
const int MAX_BUF_SIZE = 16384;
char BUFOR[MAX_BUF_SIZE];
int BUF_SIZE, BUF_POS;
char ZZZ;
const int MXN = 100010;
const int C = 262144;
const int INF = 1000000001;
int n, m;
int g[MXN];
int v[MXN];
int dist[MXN];
int p[MXN];
int kon[MXN];
int done[MXN];
pair<int, int> find(int x) {
  if (x != p[x]) {
    pair<int, int> p1 = find(p[x]);
    p[x] = p1.first;
    dist[x] += p1.second;
  }
  return make_pair(p[x], dist[x]);
}
void link(int a, int b) {
  if (find(a).first == find(b).first) return;
  a = find(a).first;
  pair<int, int> p1 = find(b);
  p[a] = p1.first;
  dist[a] = p1.second + 1;
}
void test() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &g[i]);
    p[i] = i;
  }
  for (int j = 1; j <= m; j++) scanf("%d", &v[j]);
  int last = 0;
  for (int i = 1; i <= m; i++) {
    int bi;
    scanf("%d", &bi);
    int ai = ((v[i] + last - 1) % n) + 1;
    int res = 0;
    int tmp = ai;
    int prev = ai;
    if (!done[tmp]) {
      done[tmp] = 1;
      res++;
    }
    tmp = g[tmp];
    bi--;
    while (bi > 0) {
      if (!done[tmp]) {
        done[tmp] = 1;
        res++;
        bi--;
        link(prev, tmp);
        prev = tmp;
        tmp = g[tmp];
      } else {
        pair<int, int> p1 = find(tmp);
        bi -= p1.second + 1;
        prev = p1.first;
        tmp = g[p1.first];
        if (done[tmp]) {
          if (find(prev).first != find(tmp).first)
            link(prev, tmp);
          else
            break;
        }
      }
    }
    printf("%d\n", res);
    last = res;
  }
}
int main() {
  int te = 1;
  while (te--) test();
  return 0;
}
