#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long expo_pow(long long x, long long y) {
  if (y == 0) return 1;
  y = y % (mod - 1);
  x %= mod;
  if (y == 0) y = mod - 1;
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    y >>= 1;
  }
  return res;
}
long long find_score(long long cr, long long tot) {
  double idk = double(tot) / cr;
  if (idk < 2) return 500;
  if (idk < 4) return 1000;
  if (idk < 8) return 1500;
  if (idk < 16) return 2000;
  if (idk < 32)
    return 2500;
  else
    return 3000;
}
void solve() {
  long long n;
  cin >> n;
  long long a[n][5];
  double correct[5] = {0};
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 5; j++) {
      cin >> a[i][j];
      if (a[i][j] != -1) correct[j]++;
    }
  }
  vector<long long> idk;
  for (long long j = 0; j < 5; j++) {
    if (a[0][j] == -1 and a[1][j] != -1)
      idk.push_back(-250 + a[1][j]);
    else if (a[0][j] != -1 and a[1][j] == -1)
      idk.push_back(250 - a[0][j]);
    else {
      idk.push_back(a[1][j] - a[0][j]);
    }
  }
  for (long long i = 0; i <= 120 * n; i++) {
    long long tmp = 0;
    for (long long j = 0; j < 5; j++) {
      if (a[0][j] == -1 and a[1][j] == -1) continue;
      if (a[0][j] != -1 and a[1][j] != -1 and idk[j] < 0) {
        tmp += find_score(correct[j] + i, n + i) * idk[j];
      } else {
        tmp += find_score(correct[j], n + i) * idk[j];
      }
    }
    if (tmp > 0) {
      cout << i << "\n";
      return;
    }
  }
  cout << "-1\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  long long i = 1;
  while (test--) {
    solve();
  }
}
