#include <bits/stdc++.h>
using namespace std;
long long int store[6];
long long int A[6];
long long int B[6];
double apts[6];
double bpts[6];
long long int getpts(double frac) {
  if (frac > 0.5 && frac <= 1.0) return 500ll;
  if (frac > 0.25 && frac <= 0.5) return 1000ll;
  if (frac > (1.0 / 8) && frac <= (1.0 / 4)) return 1500ll;
  if (frac > (1.0 / 16) && frac <= (1.0 / 8)) return 2000ll;
  if (frac > (1.0 / 32) && frac <= (1.0 / 16)) return 2500ll;
  if (frac >= 0 && frac <= (1.0 / 32)) return 3000ll;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= 5; j++) {
      long long int u;
      cin >> u;
      if (u != -1) store[j]++;
      if (i == 1) A[j] = u;
      if (i == 2) B[j] = u;
    }
  }
  double a_ke_pts, b_ke_pts;
  a_ke_pts = b_ke_pts = 0;
  for (long long int i = 1; i <= 5; i++) {
    long long int w = A[i];
    if (w != -1) {
      double frac = (1.0 * store[i]) / (1.0 * n);
      long long int pts = getpts(frac);
      apts[i] = 1.0 * pts * (1.0 - (w * 1.0) / 250);
      a_ke_pts += apts[i];
    }
    w = B[i];
    if (w != -1) {
      double frac = (1.0 * store[i]) / (1.0 * n);
      long long int pts = getpts(frac);
      bpts[i] = 1.0 * pts * (1.0 - (w * 1.0) / 250);
      b_ke_pts += bpts[i];
    }
  }
  if (a_ke_pts > b_ke_pts) {
    cout << 0;
    exit(0);
  }
  for (long long int j = 1; j <= 5000; j++) {
    long long int J = j;
    long long int N = n;
    N += J;
    a_ke_pts = b_ke_pts = 0;
    for (long long int i = 1; i <= 5; i++) {
      if (apts[i] > bpts[i]) {
        double nwfrac = (1.0 * (store[i]) / (1.0 * N));
        long long int pts = getpts(nwfrac);
        double nw = 1.0 * pts * (1.0 - (1.0 * A[i]) / 250);
        a_ke_pts += nw;
        if (bpts[i] > 0) {
          nw = 1.0 * pts * (1.0 - (1.0 * B[i]) / 250);
          b_ke_pts += nw;
        }
      }
      if (bpts[i] > apts[i]) {
        if (apts[i] == 0)
          J = 0;
        else
          J = j;
        double nwfrac = (1.0 * (store[i] + J) / (1.0 * N));
        long long int pts = getpts(nwfrac);
        double nw = 1.0 * pts * (1.0 - (1.0 * B[i]) / 250);
        b_ke_pts += nw;
        if (apts[i] > 0) {
          nw = 1.0 * pts * (1.0 - (1.0 * A[i]) / 250);
          a_ke_pts += nw;
        }
      }
    }
    if (a_ke_pts > b_ke_pts) {
      cout << j;
      exit(0);
    }
  }
  cout << -1 << endl;
  return 0;
}
