#include <bits/stdc++.h>
using namespace std;
int MAGIC = 1;
int TMPMAGIC = 1;
int used[110000];
int tmp[110000] = {};
int n, m;
int g[110000];
int w[110000];
int v[110000];
int b[110000];
void compress(int);
int dfs(int a, int b) {
  if (b == 0) {
    int q = !used[a];
    used[a] = MAGIC;
    return q;
  };
  if (b < 0) return 0;
  if (used[a] != MAGIC) {
    int q = !used[a];
    used[a] = MAGIC;
    if (g[a] == -1) return 0;
    q += dfs(g[a], b - w[a]);
    compress(a);
    return q;
  } else
    return 0;
}
void compress(int a) {
  TMPMAGIC++;
  if (g[a] == -1) return;
  int v = g[a];
  tmp[a] = TMPMAGIC;
  int len = w[a];
  while (true) {
    if (tmp[v] == TMPMAGIC || v == -1) {
      TMPMAGIC++;
      for (int v = g[a]; tmp[v] != TMPMAGIC && v != -1; v = g[v]) {
        g[v] = -1;
      }
      g[a] = -1;
      return;
    }
    if (!used[v]) break;
    tmp[v] = TMPMAGIC;
    len += w[v];
    v = g[v];
  }
  g[a] = v;
  len = len - w[a];
  w[a] = len + w[a];
  for (int i = g[a]; used[i]; i = g[i]) {
    len = len - w[i];
    w[i] = len + w[i];
    g[i] = v;
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &g[i]);
    g[i]--;
    w[i] = 1;
  }
  int res = 0;
  for (int i = 0; i < m; i++) scanf("%d", &v[i]);
  for (int i = 0; i < m; i++) scanf("%d", &b[i]);
  for (int i = 0; i < m; i++) {
    MAGIC = i + 1;
    int a = (v[i] + res - 1 + n) % n;
    res = dfs(a, b[i] - 1);
    printf("%d\n", res);
  }
  return 0;
}
