#include <bits/stdc++.h>
using namespace std;
static const long long N = 100005;
static long long n, m, ans, rat, nod, lst, ad[N][20], v[N], b[N], sub[N],
    adn[N];
static bool vis[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> ad[i][0];
    ad[i][0]--;
    vis[i] = false;
  }
  for (long long j = 1; j < 20; j++) {
    for (long long i = 0; i < n; i++) {
      ad[i][j] = ad[ad[i][j - 1]][j - 1];
    }
  }
  for (long long i = 0; i < m; i++) {
    cin >> v[i];
    v[i]--;
  }
  for (long long i = 0; i < m; i++) {
    cin >> b[i];
  }
  ans = 0;
  for (long long i = 0; i < m; i++) {
    nod = (ans + v[i]) % n;
    rat = b[i];
    lst = nod;
    for (long long j = 0; j < 20; j++) {
      if ((1 << j) & (rat)) {
        lst = ad[lst][j];
      }
    }
    ans = 0;
    while (rat > 0) {
      long long tmp1;
      long long tmp2;
      if (vis[nod]) {
        tmp1 = sub[nod];
        tmp2 = adn[nod];
        if (sub[nod] < rat) {
          sub[nod] = rat;
          adn[nod] = lst;
        }
      } else {
        tmp1 = 1;
        tmp2 = ad[nod][0];
        ans++;
        vis[nod] = true;
        sub[nod] = rat;
        adn[nod] = lst;
      }
      rat -= tmp1;
      nod = tmp2;
    }
    cout << ans << '\n';
  }
  return 0;
}
