#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int to[N], v[N], n, m;
int fa[N], len[N], vis[N];
int find(int x) {
  if (x == fa[x]) return x;
  int par = find(fa[x]);
  len[x] += len[fa[x]];
  return fa[x] = par;
}
void merge(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx != fy) fa[fx] = y, len[fx]++;
}
int add(int a, int b) {
  int res = 0;
  --b;
  while (b >= 0) {
    int pa = find(a);
    if (vis[pa] || (b -= len[a]) < 0) break;
    a = pa;
    vis[a] = 1, res++;
    merge(a, to[a]);
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < (n + 1); ++i) scanf("%d", to + i), fa[i] = i;
  for (int i = 0; i < (m); ++i) scanf("%d", v + i);
  int ans = 0;
  for (int i = 0; i < (m); ++i) {
    int a = ((v[i] + ans - 1) % n) + 1, b;
    scanf("%d", &b);
    printf("%d\n", ans = add(a, b));
  }
  return 0;
}
