#include <bits/stdc++.h>
using namespace std;
int n;
int num[100] = {};
long long int lossmax = -1, k, sum;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    sum = 0;
    for (int j = 0; j < 10; j++) {
      cin >> k;
      sum += k;
    }
    num[i] = sum;
  }
  sum = 0;
  for (int i = 0; i < n; i++) {
    long long int zero, max = -1000000000;
    cin >> zero;
    for (int j = 0; j < 10; j++) {
      cin >> k;
      if (num[i] > j && max < k) max = k;
    }
    if (lossmax < zero - max) lossmax = zero - max;
    sum += zero < max ? max : zero;
  }
  cout << (lossmax > 0 ? sum - lossmax : sum) << endl;
}
