#include <bits/stdc++.h>
using namespace std;
long long n, ara[101][101], pset[101];
long long get_point(long long ac, long long ttl) {
  if (ac * 2 > ttl) return 500;
  if (ac * 4 > ttl) return 1000;
  if (ac * 8 > ttl) return 1500;
  if (ac * 16 > ttl) return 2000;
  if (ac * 32 > ttl)
    return 2500;
  else
    return 3000;
}
int ok(long long fake) {
  long long p1 = 0, p2 = 0;
  for (int i = 0; i < 5; i++) {
    if (ara[0][i] == -1) {
      if (ara[1][i] >= 0)
        p2 += get_point(pset[i], n + fake) * (250 - ara[1][i]);
    } else if (ara[1][i] == -1) {
      if (ara[0][i] >= 0)
        p1 += get_point(pset[i], n + fake) * (250 - ara[0][i]);
    } else if (ara[0][i] <= ara[1][i]) {
      p1 += get_point(pset[i], n + fake) * (250 - ara[0][i]);
      p2 += get_point(pset[i], n + fake) * (250 - ara[1][i]);
    } else {
      p1 += get_point(pset[i] + fake, n + fake) * (250 - ara[0][i]);
      p2 += get_point(pset[i] + fake, n + fake) * (250 - ara[1][i]);
    }
  }
  if (p1 > p2) return 1;
  return 0;
}
int main() {
  int b, c, i, j, k, tc, t;
  int m;
  cin >> m;
  long long a = 0;
  memset(pset, 0, sizeof pset);
  for (i = 0; i < m; i++) {
    int flg = 0;
    for (j = 0; j < 5; j++) {
      scanf("%lld", &ara[i][j]);
      if (ara[i][j] >= 0) pset[j]++, flg = 1;
    }
    if (flg) a++;
  }
  n = a;
  for (long long ii = 0; ii < 100000; ii++) {
    if (ok(ii)) {
      printf("%lld\n", ii);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
