#include <bits/stdc++.h>using namespace std;int main() {ios::sync_with_stdio(false);cin.tie(0);int x, y, big=0, kk=0, ans=0;cin>>x>>y;int p[x], k[x];for(int i=0;i<x;i++){cin>>p[i];}for(int i=0;i<x;i++){cin>>k[i];}for(int i=0;i<x;i++){if(kk!=k[i]){ans+=big;big=p[i];kk=k[i];}else{big=max(big, p[i]);}}cout<<ans+big<<'\n';}