#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int f;
  int num[n];
  fill(num, num + n, 0);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 10; j++) {
      cin >> f;
      num[i] += f;
    }
  int p[n][11], tmp[n];
  bool check = false;
  int max = 0, lmax = -10000001;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) cin >> p[i][j];
    int res = -10000001;
    for (int j = 0; j < num[i] + 1; j++) {
      if (res < p[i][j]) {
        res = p[i][j];
        tmp[i] = j;
      }
      if (j != 0 && lmax < p[i][j]) lmax = p[i][j];
    }
    max += res;
  }
  for (int i = 0; i < n; i++) check |= tmp[i];
  cout << ((check) ? max : lmax) << endl;
  return 0;
}
