#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

int n,m;
int f[100][10];
long long p[100][11];

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> f[i][j];

		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> p[i][j];
		}
	}
	int count;
	long long ans, answer = -1000000001;
	for (int i = 0; i <= pow(2, 10); i++) {
		ans = 0;
		for (int k = 0; k < n; k++) {
			int num = i;
			count = 0;
			for (int j = 0; j < 10; j++) {
				if (num % 2 == 1) {
					if (f[k][j] == 1) {
						count++;
					}
				}
				num /= 2;
			}
			ans += p[k][count];
			
		}
		answer = max(ans, answer);
	}
	cout << answer << endl;
	return 0;
}