#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
T pow(T a, T b, long long m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = (ans * a) % mod;
    b /= 2;
    a = (a * a) % mod;
  }
  return ans % mod;
}
const int maxi = 3001;
int n, m, k, l, j;
int freq[122];
int arr[122][6];
int range(int x, int y) {
  if (2 * x > y) return 500;
  if (4 * x > y) return 1000;
  if (8 * x > y) return 1500;
  if (16 * x > y) return 2000;
  if (32 * x > y) return 2500;
  return 3000;
}
int check(int var) {
  long long sum1 = 0;
  long long sum2 = 0;
  for (int i = 1; i <= 5; i++) {
    if (arr[1][i] == -1) {
      if (arr[2][i] >= 0) {
        sum2 += range(freq[i], n + var) * (250 - arr[2][i]);
        continue;
      }
    }
    if (arr[1][i] >= 0) {
      if (arr[2][i] == -1) {
        sum1 += range(freq[i], n + var) * (250 - arr[1][i]);
        continue;
      }
    }
    if (arr[1][i] < arr[2][i]) {
      sum1 += range(freq[i], var + n) * (250 - arr[1][i]);
      sum2 += range(freq[i], var + n) * (250 - arr[2][i]);
    }
    if (arr[1][i] > arr[2][i]) {
      sum1 += range(freq[i] + var, n + var) * (250 - arr[1][i]);
      sum2 += range(freq[i] + var, n + var) * (250 - arr[2][i]);
    }
  }
  return (sum1 > sum2) ? true : false;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < 122; i++) freq[i] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 5; j++) {
      scanf("%d", &arr[i][j]);
      if (arr[i][j] >= 0) ++freq[j];
    }
  }
  for (int i = 0; i <= 10000; i++) {
    if (check(i) == true) {
      printf("%d\n", i);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
