#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const long double PI = acos((long double)-1);
const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1};
const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1},
          d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int MAXN = 100005;
int ngh[MAXN + 5];
int v[MAXN + 5], b[MAXN + 5];
int res[MAXN + 5];
bool done[MAXN + 5];
int solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> ngh[i];
  for (int i = 1; i <= m; i++) cin >> v[i];
  for (int i = 1; i <= m; i++) cin >> b[i];
  vector<int> jarak(MAXN + 5, 1);
  res[0] = 0;
  for (int i = 1; i <= m; i++) {
    int a = (v[i] + res[i - 1] - 1) % n + 1;
    int sum = 0;
    int statA = a;
    int tempB = b[i];
    int tempIdx = a;
    while (b[i] > 0) {
      if (!done[a]) {
        sum += 1;
        done[a] = 1;
      }
      if (b[i] != tempB && statA == a) break;
      b[i] -= jarak[a];
      if (a == ngh[a]) break;
      a = ngh[a];
      if (done[ngh[tempIdx]]) {
        jarak[tempIdx] += jarak[ngh[tempIdx]];
        ngh[tempIdx] = ngh[ngh[tempIdx]];
      }
      tempIdx = a;
    }
    cout << (res[i] = sum) << endl;
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t = 1, x;
  for (int tc = 1; tc <= t; tc++) {
    x = solve();
  }
  return 0;
}
