#include <bits/stdc++.h>
const bool debug = false;
using namespace std;
long long powmod(long long a, long long b, long long MOD) {
  long long res = 1;
  a %= MOD;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}
void buginfo(const char* f, ...) {
  if (!debug) return;
  va_list al;
  va_start(al, f);
  vprintf(f, al);
  va_end(al);
}
const int maxn = 130;
const int inf = 1e9 + 7;
int n, a[maxn][5], pas[5];
int getsc(double d) {
  if (d > 1.0 / 2) return 500;
  if (d > 1.0 / 4) return 1000;
  if (d > 1.0 / 8) return 1500;
  if (d > 1.0 / 16) return 2000;
  if (d > 1.0 / 32) return 2500;
  return 3000;
}
bool check(int d) {
  int buf[5];
  copy(pas, pas + 5, buf);
  int s1 = 0, s2 = 0;
  for (int i = 0; i < 5; ++i) {
    if (a[0][i] != -1 && a[1][i] != -1 && a[0][i] > a[1][i]) pas[i] += d;
    int t = getsc(1.0 * pas[i] / (n + d));
    if (a[0][i] != -1) s1 += t * (1.0 - a[0][i] / 250.0);
    if (a[1][i] != -1) s2 += t * (1.0 - a[1][i] / 250.0);
  }
  copy(buf, buf + 5, pas);
  return s1 > s2;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 5; ++j) scanf("%d", &a[i][j]);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 5; ++j)
      if (a[i][j] != -1) ++pas[j];
  for (int i = 0; i < 50000; ++i)
    if (check(i)) return 0 * printf("%d\n", i);
  return 0 * printf("-1\n");
}
