#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int K = 1e6 + 7;
const int mod = 1e9 + 7;
int n, ans = -1, a[200][10], sum[10];
int sc(int k, int x) {
  double ta, tb;
  if (a[2][k] == -1 && a[1][k] != -1)
    tb = 1.0 - a[1][k] / 250.0;
  else if (a[1][k] == -1 && a[2][k] != -1)
    tb = -1.0 + a[2][k] / 250.0;
  else
    tb = (a[2][k] - a[1][k]) / 250.0;
  if (tb > 0 || a[1][k] == -1)
    ta = sum[k] * 1.0 / (n + x);
  else
    ta = (sum[k] + x) * 1.0 / (n + x);
  if (ta > 0.5)
    return 500 * tb;
  else if (ta > 0.25)
    return 1000 * tb;
  else if (ta > 0.125)
    return 1500 * tb;
  else if (ta > pow(2.0, -4.0))
    return 2000 * tb;
  else if (ta > pow(2.0, -5.0))
    return 2500 * tb;
  else
    return 3000 * tb;
}
bool check(int x) {
  int ret = 0;
  for (int i = 1; i <= 5; i++) ret += sc(i, x);
  return ret > 0;
}
int main(void) {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 5; j++)
      scanf("%d", &a[i][j]), a[i][j] >= 0 ? sum[j]++ : 0;
  for (int i = 0; i <= 4000 && ans == -1; i++)
    if (check(i)) ans = i;
  printf("%d\n", ans);
  return 0;
}
