#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int n;
int v[maxn][10];
int num[5];
int solve(int x, int flag, int y) {
  if (v[flag][y] == -1) return 0;
  int tmp;
  if (v[0][y] == -1 || v[1][y] == -1 || v[0][y] < v[1][y])
    tmp = num[y];
  else
    tmp = x - n + num[y];
  int ans = 500;
  for (int i = 2; i <= 32; i *= 2) {
    if (tmp * i > x)
      break;
    else
      ans += 500;
  }
  return ans * (1.0 - v[flag][y] / 250.0);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 5; j++) {
      scanf("%d", &v[i][j]);
      if (v[i][j] != -1) num[j]++;
    }
  int M = 100005 + n;
  int i;
  for (i = n; i < M; i++) {
    int V = 0, P = 0;
    for (int j = 0; j < 5; j++) V += solve(i, false, j);
    for (int j = 0; j < 5; j++) P += solve(i, true, j);
    if (V > P) return 0 * printf("%d\n", i - n);
  }
  printf("-1\n");
}
