#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 2e5 + 7;
int n;
int a[120][5], cnt[5];
int getScore(int pid, int id, int sum) {
  if (a[id][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 = sum - n + cnt[pid];
  for (int i = 2; i <= 32; i *= 2) {
    if (solved * i > sum)
      break;
    else
      maxPoint += 500;
  }
  return maxPoint * (1 - a[id][pid] / 250.0);
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 5; j++) {
      cin >> a[i][j];
      if (a[i][j] != -1) cnt[j]++;
    }
  for (int i = n; i < 120 * n + 1; i++) {
    int A = 0, B = 0;
    for (int j = 0; j < 5; j++) A += getScore(j, 0, i);
    for (int j = 0; j < 5; j++) B += getScore(j, 1, i);
    if (A > B) {
      cout << i - n << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
