// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define patkan 9
#define tisic 47
#define soclose 1e-7
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define chocolate win
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):(x))
// mylittlepony
using namespace std;
int main() {
// freopen("nochange.in","r",stdin);
// freopen("nochange.out","w",stdout);
cin.sync_with_stdio(0);
int K,N;
cin >> K >> N;
vector<int> C(K), P(N);
for(int i =0; i < K; i++) cin >> C[i];
vector<int> Sc((1<<K),0);
for(int i =0; i < (1<<K); i++) for(int j =K-1; j >= 0; j--) {
if((1<<j) <= i) break;
Sc[i+(1<<j)] =Sc[i]+C[j];}
for(int i =0; i < N; i++) cin >> P[i];
vector<int> Sp(N+1,0);
for(int i =0; i < N; i++) Sp[i+1] =Sp[i]+P[i];
// ak som prvych i zaplatil, co prve nezaplatim na mincu j?
vector< vector<int> > D(N+1, vector<int>(K,-1));
for(int i =0; i < K; i++) {
int a =0; // prve co nezaplatim
for(int j =0; j < N; j++) {
while(a < N) {
if(Sp[a+1]-Sp[j] <= C[i]) a++;
else break;}
D[j][i] =a;}
D[N][i] =N;}
// dynamika: kolko najviac zaplatim na mnozinu minci M?
vector<int> res((1<<K),0);
for(int i =1; i < (1<<K); i++)
for(int j =0; j < K; j++) if((i&(1<<j)) != 0)
res[i] =max(res[i],D[res[i^(1<<j)]][j]);
int ans =-1;
for(int i =0; i < (1<<K); i++)
if(res[i] == N) ans =max(ans,Sc[(1<<K)-1]-Sc[i]);
cout << ans << "\n";
return 0;}
// look at my code
// my code is amazing
Ly8gaW9zdHJlYW0gaXMgdG9vIG1haW5zdHJlYW0KI2luY2x1ZGUgPGNzdGRpbz4KLy8gYml0Y2ggcGxlYXNlCiNpbmNsdWRlIDxpb3N0cmVh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7CiAgICAJU2NbaSsoMTw8aildID1TY1tpXStDW2pdO30KICAgIGZvcihpbnQgaSA9MDsgaSA8IE47IGkrKykgY2luID4+IFBbaV07CiAgICB2ZWN0b3I8aW50PiBTcChOKzEsMCk7CiAgICBmb3IoaW50IGkgPTA7IGkgPCBOOyBpKyspIFNwW2krMV0gPVNwW2ldK1BbaV07CiAgICAKICAgIC8vIGFrIHNvbSBwcnZ5Y2ggaSB6YXBsYXRpbCwgY28gcHJ2ZSBuZXphcGxhdGltIG5hIG1pbmN1IGo/CiAgICB2ZWN0b3I8IHZlY3RvcjxpbnQ+ID4gRChOKzEsIHZlY3RvcjxpbnQ+KEssLTEpKTsKICAgIGZvcihpbnQgaSA9MDsgaSA8IEs7IGkrKykgewogICAgCWludCBhID0wOyAvLyBwcnZlIGNvIG5lemFwbGF0aW0KICAgIAlmb3IoaW50IGogPTA7IGogPCBOOyBqKyspIHsKICAgIAkJd2hpbGUoYSA8IE4pIHsKICAgIAkJCWlmKFNwW2ErMV0tU3Bbal0gPD0gQ1tpXSkgYSsrOwogICAgCQkJZWxzZSBicmVhazt9CiAgICAJCURbal1baV0gPWE7fQogICAgCURbTl1baV0gPU47fQogICAgCiAgICAvLyBkeW5hbWlrYToga29sa28gbmFqdmlhYyB6YXBsYXRpbSBuYSBtbm96aW51IG1pbmNpIE0/CiAgICB2ZWN0b3I8aW50PiByZXMoKDE8PEspLDApOwogICAgZm9yKGludCBpID0xOyBpIDwgKDE8PEspOyBpKyspIAogICAgCWZvcihpbnQgaiA9MDsgaiA8IEs7IGorKykgaWYoKGkmKDE8PGopKSAhPSAwKQogICAgCQlyZXNbaV0gPW1heChyZXNbaV0sRFtyZXNbaV4oMTw8aildXVtqXSk7CiAgICAKICAgIGludCBhbnMgPS0xOwogICAgZm9yKGludCBpID0wOyBpIDwgKDE8PEspOyBpKyspCiAgICAJaWYocmVzW2ldID09IE4pIGFucyA9bWF4KGFucyxTY1soMTw8SyktMV0tU2NbaV0pOwogICAgY291dCA8PCBhbnMgPDwgIlxuIjsKICAgIHJldHVybiAwO30KICAgICAgICAKLy8gbG9vayBhdCBteSBjb2RlCi8vIG15IGNvZGUgaXMgYW1hemluZw==