#include <bits/stdc++.h>
long passed[5], n;
long winner[5], loser[5], cheat[5];
bool check(long x) {
  long winner_score = 0, loser_score = 0;
  for (long i = 0; i < 5; i++) {
    long m = passed[i] + cheat[i] * x;
    long a = 3000;
    for (long mul = 32; mul >= 1; mul /= 2, a -= 500)
      if ((long long)mul * m <= n + x) break;
    long d = a / 250;
    if (winner[i] != -1) winner_score += a - d * winner[i];
    if (loser[i] != -1) loser_score += a - d * loser[i];
  }
  return winner_score > loser_score;
}
void solve() {
  for (long i = 0; i < 5; i++)
    if (loser[i] != -1 && winner[i] > loser[i]) cheat[i] = 1;
  long ans;
  for (ans = 0; ans < n * 32 + 5; ans++)
    if (check(ans)) break;
  if (ans == n * 32 + 5) ans = -1;
  printf("%ld\n", ans);
}
int main() {
  scanf("%ld", &n);
  for (long i = 0; i < n; i++) {
    long a[5];
    scanf("%ld%ld%ld%ld%ld", &a[0], &a[1], &a[2], &a[3], &a[4]);
    if (i == 0)
      for (long j = 0; j < 5; j++) winner[j] = a[j];
    if (i == 1)
      for (long j = 0; j < 5; j++) loser[j] = a[j];
    for (long j = 0; j < 5; j++)
      if (a[j] != -1) passed[j]++;
  }
  solve();
  return 0;
}
