#include <bits/stdc++.h>
const long long MOD = 1000000007;
using namespace std;
int n, a[120][5], cnt[5];
int getScore(int pid, bool isPetya, int participants) {
  if (a[isPetya][pid] == -1) return 0;
  int maxPoint = 500, solved;
  if (a[0][pid] == -1 || a[1][pid] == -1 || a[0][pid] < a[1][pid]) {
    solved = cnt[pid];
  } else {
    solved = participants - n + cnt[pid];
  }
  for (int i = 2; i <= 32; i *= 2)
    if (solved * i > participants)
      break;
    else
      maxPoint += 500;
  return maxPoint * (1.0 - a[isPetya][pid] / 250.0);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 5; j++) {
      scanf("%d", &a[i][j]);
      if (a[i][j] != -1) cnt[j]++;
    }
  vector<int> v;
  v.push_back(n);
  for (int i = 0; i < 5; i++)
    for (int j = 2; j <= 32; j *= 2)
      if (cnt[i] * j >= n) v.push_back(cnt[i] * j);
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    if (i && v[i] == v[i - 1]) continue;
    int Vasya = 0, Petya = 0;
    for (int j = 0; j < 5; j++) Vasya += getScore(j, false, v[i]);
    for (int j = 0; j < 5; j++) Petya += getScore(j, true, v[i]);
    if (Vasya > Petya) {
      printf("%d\n", v[i] - n);
      return 0;
    }
  }
  printf("-1\n");
}
