#include <bits/stdc++.h>
using namespace std;
const int maxn = 200;
int s[maxn][6], n;
int cnt[maxn];
int get_score(int id, int f, int a) {
  if (s[f][id] == -1) return 0;
  int sum = 0;
  if (s[1][id] == -1 || s[2][id] == -1 || s[1][id] < s[2][id])
    sum = cnt[id];
  else
    sum = cnt[id] + a;
  int score = 500;
  for (int i = 2; i <= 32; i *= 2) {
    if (sum * i > n + a) {
      break;
    } else {
      score += 500;
    }
  }
  return score * (250.0 - s[f][id]) * 250.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]);
  memset(cnt, 0, sizeof(cnt));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 5; j++)
      if (s[i][j] != -1) cnt[j]++;
  int sum1 = 0, sum2 = 0;
  int ss = -1;
  for (int v = 0; v <= 120 * 32; v++) {
    sum1 = 0, sum2 = 0;
    for (int j = 1; j <= 5; j++) {
      sum1 += get_score(j, 1, v);
      sum2 += get_score(j, 2, v);
    }
    if (sum1 > sum2) {
      ss = v;
      break;
    }
  }
  printf("%d\n", ss);
}
