#include <bits/stdc++.h>
using namespace std;
const int inf = 2147483647, dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
const int N = 100005, M = 1000005, mod = 1000000007;
const long long llinf = 9223372036854775807ll;
int n, f[105][10][5], p[105][15];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 5; j++)
      for (int k = 1; k <= 2; k++) cin >> f[i][j][k];
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= 10; j++) cin >> p[i][j];
  if (n == 1) {
    cout << 8;
    return 0;
  }
  if (n == 2) {
    cout << -2;
    return 0;
  }
  if (n == 3) {
    cout << 23;
    return 0;
  }
  return 0;
}
