include <bits/stdc++.h>
using namespace std;
define CLR(a,b) memset(a,(b),sizoeof(a))
define sf(i) scanf("%d",&i)
define LL long long
const int MAXN = 2e5+10;
const int INF = 0x3f3f3f3f;
const int mod = 19260817;
int sum[MAXN], arr[MAXN], f[MAXN], cnt[MAXN];
vector<int> v[MAXN];</int>
int main()
{
// ios::sync_with_stdio(false);
int n, m, x;
sf(n); sf(m);
for(int i = 2; i <= n; i++) {
sf(x); v[x].push_back(i);
f[i] = x;
}
int Hash = 0; f[1] = 0;
for(int i = 1; i <= m; i++) { int ans = 0; sf(x); arr[x]++; cnt[x]++; sum[x] += int(v[x].size()); sum[x] %= mod; arr[f[x]]++; sum[f[x]]++; sum[f[f[x]]]++; sum[0] = 0; cnt[0] = 0; arr[0] = 0; ans = (arr[x]+arr[f[x]]+sum[x]+cnt[f[x]]+cnt[f[f[x]]])%mod; Hash = (Hash+(LL)ans*i%mod)%mod; } printf("%d\n",Hash);
return 0;
}