#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int f[100][11] = {};
  int p[100][11] = {};
  int n;
  int fsum[100] = {};
  int cnt = 0;
  int i;
  int psum[100] = {};
  int pmax = -100000000;
  cin >> n;
  for (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];
    }
  }
  for (i = 0; i < n; i++) {
    cnt = 0;
    for (int j = 0; j < 10; j++) {
      if (f[i][j] == 1) {
        cnt++;
      }
    }
    fsum[i] += cnt;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= fsum[i]; j++) {
      pmax = max(p[i][j], pmax);
    }
    psum[i] = pmax;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = psum[i];
  }
  cout << ans << endl;
  return 0;
}
