#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
const int N = 122;
int n, a[5][N], cnt[5];
int points(ld x) {
  if (x <= 1.0 / 32.0) return 3000;
  if (x <= 1.0 / 16.0) return 2500;
  if (x <= 1.0 / 8.0) return 2000;
  if (x <= 1.0 / 4.0) return 1500;
  if (x <= 1.0 / 2.0) return 1000;
  return 500;
}
bool ok(int num) {
  int point = 0;
  for (int i = (0); i <= (4); ++i) {
    if (a[i][0] == -1 && a[i][1] == -1) continue;
    ld tmp;
    if (a[i][0] == -1)
      tmp = (ld)(cnt[i]) / (ld)(n + num);
    else if (a[i][1] == -1)
      tmp = (ld)(cnt[i]) / (ld)(n + num);
    else if (a[i][1] < a[i][0])
      tmp = (ld)(cnt[i] + num) / (ld)(n + num);
    else
      tmp = (ld)(cnt[i]) / (ld)(n + num);
    int p = points(tmp), p1 = p / 250;
    if (a[i][0] == -1)
      point -= p - p1 * a[i][1];
    else if (a[i][1] == -1)
      point += p - p1 * a[i][0];
    else
      point += p1 * (a[i][1] - a[i][0]);
  }
  return point > 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = (0); i <= (n - 1); ++i)
    for (int j = (0); j <= (4); ++j) {
      cin >> a[j][i];
      if (a[j][i] != -1) cnt[j]++;
    }
  int l = 0, r = 1e9 + 7;
  for (int l = (0); l <= (1e7); ++l)
    if (ok(l)) {
      cout << l;
      return 0;
    }
  cout << -1;
  return 0;
}
