#include <bits/stdc++.h>
using namespace std;
int per[200][5];
int num[5];
int n;
int getscore(int idx, bool is, int nn) {
  if (per[is][idx] == -1) return 0;
  int solved = 0;
  if (per[0][idx] == -1 || per[1][idx] == -1 || per[0][idx] <= per[1][idx]) {
    solved = num[idx];
  } else {
    solved = nn - n + num[idx];
  }
  int maxn = 500;
  for (int i = 2; i <= 32; i *= 2) {
    if (solved * i > nn)
      break;
    else
      maxn += 500;
  }
  return maxn * (1.0 - per[is][idx] / 250.0);
}
int main() {
  scanf("%d", &n);
  memset(num, 0, sizeof(num));
  memset(per, 0, sizeof(per));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5; j++) {
      scanf("%d", &per[i][j]);
      if (per[i][j] != -1) num[j]++;
    }
  }
  vector<int> v;
  v.clear();
  v.push_back(n);
  for (int i = 0; i < 5; i++) {
    for (int j = 2; j <= 32; j *= 2)
      if (num[i] * j >= n) v.push_back(num[i] * j);
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    if (i && v[i] == v[i - 1]) continue;
    int score1 = 0, score2 = 0;
    for (int j = 0; j < 5; j++) score1 += getscore(j, false, v[i]);
    for (int j = 0; j < 5; j++) score2 += getscore(j, true, v[i]);
    if (score1 > score2) {
      cout << v[i] - n << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
