#include <bits/stdc++.h>
using namespace std;
unsigned long long M = 1e9 + 7;
int b, m, k, tc;
int lj, lj2;
string s;
int g[100005];
vector<int> ig[100005];
int v[100005];
int res[100005];
int lompat[100005];
int vis[100005];
int berita;
int tempres = 0;
void pathComp(int berita, int a) {
  if (berita <= 0) {
    return;
  }
  if (!vis[a]) {
    vis[a] = 1;
    tempres++;
  }
  if (a != g[a]) {
    pathComp(berita - lompat[a], g[a]);
    if (a != g[a]) {
      int bef;
      int af = g[a];
      while (ig[a].size() > 0) {
        int uk = ig[a].size();
        bef = ig[a][uk - 1];
        g[bef] = af;
        ig[af].push_back(bef);
        ig[a].pop_back();
        lompat[bef] = lompat[bef] + lompat[a];
      }
    }
  } else {
    berita = 0;
    return;
  }
}
void init() {
  for (int i = 0; i < b + 2; i++) {
    lompat[i] = 1;
  }
}
void solve() {
  init();
  for (int i = (1); i != (m + ((m - 1) / abs(m - 1)));
       i += (m - 1) / abs(m - 1)) {
    cin >> berita;
    int ai = ((v[i] + res[i - 1] - 1) % b) + 1;
    tempres = 0;
    pathComp(berita, ai);
    res[i] = tempres;
  }
  for (int i = (1); i != (m + ((m - 1) / abs(m - 1)));
       i += (m - 1) / abs(m - 1)) {
    cout << res[i] << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  cin >> b >> m;
  for (int i = 0; i < (b); i++) {
    cin >> g[i + 1];
    ig[g[i + 1]].push_back(i + 1);
  }
  for (int i = 0; i < (m); i++) {
    cin >> v[i + 1];
  }
  solve();
}
