#include <bits/stdc++.h>
using namespace std;
long long int n, arr[123][12], brr[123];
long long int solve(long long int a, long long int b) {
  if (a < 2) return (2 * b);
  if (a < 4) return (4 * b);
  if (a < 8) return (6 * b);
  if (a < 16) return (8 * b);
  if (a < 32) return (10 * b);
  return (12 * b);
}
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 5; j++) {
      scanf("%lld", &arr[i][j]);
      if (arr[i][j] != -1) brr[j]++;
    }
  }
  long long int ans = -1;
  long long int lo = n, hi = n + 1e9 + 7;
  for (int mi = 10000; mi >= n; mi--) {
    long long int val1 = 0, val2 = 0;
    for (int i = 1; i <= 5; i++) {
      if (arr[1][i] == -1 && arr[2][i] == -1)
        continue;
      else if (arr[2][i] == -1) {
        long long int a = mi / brr[i];
        long long int b = 250 - arr[1][i];
        val1 += solve(a, b);
      } else if (arr[1][i] == -1) {
        long long int a = mi / (brr[i]);
        long long int b = 250 - arr[2][i];
        val2 += solve(a, b);
      } else {
        if (arr[1][i] < arr[2][i]) {
          long long int a = mi / brr[i];
          long long int b = 250 - arr[1][i];
          val1 += solve(a, b);
          b = 250 - arr[2][i];
          val2 += solve(a, b);
        } else if (arr[1][i] == arr[2][i]) {
          long long int a = mi / brr[i];
          long long int b = 250 - arr[1][i];
          val1 += solve(a, b);
          val2 += solve(a, b);
        } else {
          long long int a = mi / (mi - n + brr[i]);
          long long int b = 250 - arr[1][i];
          val1 += solve(a, b);
          b = 250 - arr[2][i];
          val2 += solve(a, b);
        }
      }
    }
    if (val1 > val2) ans = mi - n;
  }
  printf("%lld\n", ans);
}
