#include <bits/stdc++.h>
using namespace std;
pair<int, int> ge[100005];
int visited[100005], cnt, ans[100005], v[100005], b[100005];
int mi;
long long res = 0;
int dfs(int id, int e) {
  visited[id]++;
  if (ans[id] == 0 && e > 0) {
    res++;
    ans[id] = 1;
  }
  if (e >= ge[id].second) {
    if (ge[id].first == -1 || visited[ge[id].first] == 1) {
      ge[id].first = -1;
      visited[id]--;
      return -1;
    }
    if (e - ge[id].second >= ge[ge[id].first].second) {
      ge[id].first = dfs(ge[id].first, e - ge[id].second);
      ge[id].second = e - mi;
      visited[id]--;
      return ge[id].first;
    } else {
      mi = e - ge[id].second;
      visited[id]--;
      return ge[id].first;
    }
  }
  mi = e;
  visited[id]--;
  return id;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, a, tg;
  long long prev = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    visited[i] = 0;
    ans[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> a;
    ge[i] = make_pair(a - 1, 1);
  }
  for (int i = 0; i < m; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < m; i++) {
    mi = 0;
    res = 0;
    tg = (v[i] + prev - 1) % n;
    if (ge[tg].first != -1) {
      dfs(tg, b[i]);
    }
    cout << res << endl;
    prev = res;
  }
  return 0;
}
