
#include <iostream>
#include <algorithm>
using namespace std;
int numSegments, numNotes, pos = -1, maxMatches = 0;
int lowTones[8] = {0}, highTones[8], segmentRequirements[8];
void matchTones(int noteIdx) {
if (noteIdx == numNotes) {
int matched = 0;
for (int i = 0; i < numSegments; i++) {
if (lowTones[i] == segmentRequirements[i])
matched++;
}
maxMatches = max(maxMatches, matched);
return;
}
for (int i = 0; i < numSegments; i++) {
if (lowTones[i] + highTones[noteIdx] <= segmentRequirements[i]) {
lowTones[i] += highTones[noteIdx];
matchTones(noteIdx + 1);
lowTones[i] -= highTones[noteIdx];
}
}
matchTones(noteIdx + 1);
return;
}
int main() {
cin >> numSegments >> numNotes;
for (int i = 0; i < numSegments; i++)
cin >> segmentRequirements[i];
for (int i = 0; i < numNotes; i++)
cin >> highTones[i];
matchTones(0);
cout << maxMatches;
return 0;
}