#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long INF = 1e9;
const int N = 200031;
int n, a[N][6];
int people_solved[N];
int should_add[N];
int get_group(int problem) {
  for (int i = 1; i <= 5; i++) {
    if (people_solved[problem] * (1 << i) > n) return i;
  }
  return 6;
}
int get_score(int person, int problem) {
  if (a[person][problem] == -1) return 0;
  int group = get_group(problem);
  int base_score = group * 500;
  return base_score - base_score / 250 * a[person][problem];
}
int eval(int person_id) {
  int res = 0;
  for (int j = 1; j <= 5; j++) {
    res += get_score(person_id, j);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 5; j++) {
      cin >> a[i][j];
      if (a[i][j] != -1) people_solved[j]++;
    }
  }
  for (int i = 1; i <= 5; i++) {
    if (a[1][i] == -1) continue;
    if (get_score(1, i) < get_score(2, i))
      should_add[i] = 1;
    else
      should_add[i] = 0;
  }
  if (eval(1) > eval(2)) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 1; i <= 100000; i++) {
    n++;
    for (int j = 1; j <= 5; j++) {
      if (should_add[j]) {
        people_solved[j]++;
      }
    }
    if (eval(1) > eval(2)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  cin.get();
  cin.get();
  return 0;
}
