#include <bits/stdc++.h>
using namespace std;
int n, s[125][6];
int suc[6];
void attempt(int num) {
  int ttl = n + num;
  int A = 0, B = 0;
  for (int i = (1); i <= (5); i++) {
    int new_suc = suc[i], point;
    if (s[1][i] > s[2][i] && s[2][i] != -1) new_suc += num;
    if (new_suc * 2 > ttl)
      point = 500;
    else if (new_suc * 4 > ttl)
      point = 1000;
    else if (new_suc * 8 > ttl)
      point = 1500;
    else if (new_suc * 16 > ttl)
      point = 2000;
    else if (new_suc * 32 > ttl)
      point = 2500;
    else
      point = 3000;
    if (s[1][i] != -1) A += point / 250 * (250 - s[1][i]);
    if (s[2][i] != -1) B += point / 250 * (250 - s[2][i]);
  }
  if (A > B) {
    printf("%d\n", num);
    exit(0);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (5); j++) {
      scanf("%d", &s[i][j]);
      if (s[i][j] != -1) suc[j]++;
    }
  for (int i = (0); i <= (5000); i++) attempt(i);
  printf("-1\n");
  return 0;
}
