#include <bits/stdc++.h>
using namespace std;
int a[150][150];
int cnt[10];
int n;
int getscore(int id, bool flag, int s) {
  if (a[flag][id] == -1) return 0;
  int sum;
  if (a[0][id] == -1 || a[1][id] == -1 || a[0][id] < a[1][id])
    sum = cnt[id];
  else
    sum = cnt[id] + s;
  int score = 500;
  for (int i = 2; i <= 32; i *= 2) {
    if (sum * i > n + s)
      break;
    else
      score += 500;
  }
  return score * (250.0 - a[flag][id]) / 250.0;
}
int main() {
  ios::sync_with_stdio(false);
  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 = 0; i < 50000; ++i) {
    int a1 = 0, a2 = 0;
    for (int j = 0; j < 5; ++j) a1 += getscore(j, 0, i);
    for (int j = 0; j < 5; ++j) a2 += getscore(j, 1, i);
    if (a1 > a2) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}
