#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
ll cost[1000009];
int id[1000004],a[1000009];
ll res[1000009];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
ll sum=0;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++){cin>>cost[i];cost[i]=min(cost[i],0LL);sum+=cost[i];}
for(int i=1;i<=m;i++)
{
res[i]=-10000000000000000;
int x;
cin>>x;
id[x]=i;}
for(int i=0;i<n;i++)
{
if(id[a[i]]==0)continue;
res[id[a[i]]]=max(res[id[a[i]]],res[id[a[i]]-1]+cost[i]);
}
cout<<sum-res[m];
}
Copy