#include <bits/stdc++.h>
using namespace std;
long long n, v[222][5], cnt[5], ans;
long long getScore(double solvedCnt, double totalCnt) {
  if (solvedCnt > totalCnt / 2.0) return 500;
  if (solvedCnt > totalCnt / 4.0) return 1000;
  if (solvedCnt > totalCnt / 8.0) return 1500;
  if (solvedCnt > totalCnt / 16.0) return 2000;
  if (solvedCnt > totalCnt / 32.0) return 2500;
  return 3000;
}
void chk(long long idx, long long add, long long delta) {
  if (idx == 5) {
    if (delta > 0) ans = 1;
    return;
  }
  long long a = getScore((double)(cnt[idx]), (double)(n + add));
  long long b = getScore((double)(cnt[idx]), (double)(n + add));
  if (v[0][idx] == -1) a = 0;
  if (v[1][idx] == -1) b = 0;
  a = a * (250 - v[0][idx]) / 250;
  b = b * (250 - v[1][idx]) / 250;
  chk(idx + 1, add, delta + a - b);
  if (v[0][idx] != -1) {
    a = getScore((double)(cnt[idx] + add), (double)(n + add));
    b = getScore((double)(cnt[idx] + add), (double)(n + add));
    if (v[0][idx] == -1) a = 0;
    if (v[1][idx] == -1) b = 0;
    a = a * (250 - v[0][idx]) / 250;
    b = b * (250 - v[1][idx]) / 250;
    chk(idx + 1, add, delta + a - b);
  }
}
int main() {
  scanf("%lld", &n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 5; j++) {
      scanf("%lld", &v[i][j]);
      if (v[i][j] != -1) cnt[j]++;
    }
  for (long long i = 0; i < 5000; i++) {
    chk(0, i, 0);
    if (ans) printf("%lld\n", i), exit(0);
  }
  printf("-1\n");
}
