#include <bits/stdc++.h>
using std::abs;
using std::bitset;
using std::cerr;
using std::cin;
using std::copy;
using std::cout;
using std::endl;
using std::fill;
using std::fixed;
using std::greater;
using std::lower_bound;
using std::map;
using std::max;
using std::min;
using std::next_permutation;
using std::pair;
using std::priority_queue;
using std::queue;
using std::reverse;
using std::rotate;
using std::set;
using std::sort;
using std::string;
using std::swap;
using std::unique;
using std::unordered_map;
using std::unordered_set;
using std::upper_bound;
using std::vector;
int const INF = (int)1e9;
long long const INFL = (long long)1e18;
long double const PI = 3.1415926535897932384626433832795028;
bool isPrime(int x) {
  for (int a = 2; a * a <= x; ++a) {
    if (x % a == 0) {
      return false;
    }
  }
  return true;
}
int const N = 100100;
int len[N];
int g[N], next[N];
int find(int v) {
  if (next[v] != v) {
    int root = find(next[v]);
    len[v] += len[next[v]];
    next[v] = root;
  }
  return next[v];
}
int v[N], res[N];
bool did[N];
int calc(int a, int b) {
  int ret = 0;
  find(a);
  b -= len[a];
  a = next[a];
  while (b > 0 && !did[a]) {
    ++ret;
    did[a] = true;
    next[a] = find(g[a]);
    len[a] = 1 + len[g[a]];
    b -= len[a];
    a = find(g[a]);
  }
  return ret;
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    next[i] = i;
    len[i] = 0;
    cin >> g[i];
    --g[i];
  }
  for (int i = 1; i <= m; ++i) {
    cin >> v[i];
  }
  for (int i = 1; i <= m; ++i) {
    int b;
    cin >> b;
    int a = (v[i] + res[i - 1] - 1) % n;
    res[i] = calc(a, b);
  }
  for (int i = 1; i <= m; ++i) {
    cout << res[i] << "\n";
  }
}
int main() { solve(); }
