#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T a) {
  return ((a < 0) ? -a : a);
}
template <typename T>
inline T sqr(T a) {
  return a * a;
}
const int N = 100009;
const int logN = 22;
const int sqrN = 450;
const int MOD = 1000000007;
const int INF = 1e9 + 100;
const long long INF64 = 1e14;
const long double PI = 3.1415926535897932384626433832795;
const long double eps = 1e-9;
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
int n, m;
int to[N];
int len[N];
int b[N], v[N];
int used[N], T;
bool ok[N];
int next(int v) {
  used[v] = T;
  if (!used[to[v]]) return to[v];
  if (used[to[v]] == T) return to[v] = n;
  next(to[v]);
  len[v] += len[to[v]];
  return to[v] = to[to[v]];
}
int main() {
  srand(time(NULL));
  cout << setprecision(10) << fixed;
  cerr << setprecision(10) << fixed;
  cin >> n >> m;
  for (int i = 0; i < (int)(n); ++i) cin >> to[i], --to[i], len[i] = 1;
  for (int i = 0; i < (int)(m); ++i) cin >> v[i];
  for (int i = 0; i < (int)(m); ++i) cin >> b[i];
  int res = 0;
  for (int i = 0; i < (int)(m); ++i) {
    int u = (v[i] + res - 1) % n;
    int ans = 0;
    while (b[i] > 0 && u != n) {
      ++T;
      ans += (ok[u] == false);
      next(u);
      ok[u] = true;
      b[i] -= len[u];
      u = to[u];
    }
    res = ans;
    cout << ans << endl;
  }
  return 0;
}
