#include<bits/stdc++.h>
using namespace std;
int u[100000],v[100000],dp[100000];
int main(){
int a,b;
cin >> a >> b;
for(int i = 1;i <= b;i ++){
cin >> u[i];
}
for(int i = 1;i <= a;i ++){
cin >> v[i];
dp[i] = v[i];
}
for(int i = 2;i <= a;i ++){
int ans = 0;
for(int j = 1;j <= b;j ++){
ans = max(ans , dp[max(i - u[j],0)]);
}
dp[i] += ans;
}
cout << dp[a];
return 0;
}