#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
  return cout << "(" << p.first << ", " << p.second << ")";
}
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v) {
  cout << "[";
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << ", ";
    cout << v[i];
  }
  return cout << "]";
}
mt19937 rng(steady_clock::now().time_since_epoch().count());
void usaco(string filename) {
#pragma message("be careful, freopen may be wrong")
  freopen((filename + ".in").c_str(), "r", stdin);
  freopen((filename + ".out").c_str(), "w", stdout);
}
const long long mod = 998244353;
long long madd(long long a, long long b) { return (a + b) % mod; }
long long msub(long long a, long long b) {
  return (((a - b) % mod) + mod) % mod;
}
long long mmul(long long a, long long b) {
  return ((a % mod) * (b % mod)) % mod;
}
long long mpow(long long base, long long exp) {
  long long res = 1;
  while (exp) {
    if (exp % 2 == 1) {
      res = (res * base) % mod;
    }
    exp >>= 1;
    base = (base * base) % mod;
  }
  return res;
}
long long minv(long long base) { return mpow(base, mod - 2); }
long long mdiv(long long a, long long b) { return mmul(a, minv(b)); }
long long gcd(long long x, long long y) {
  if (x == 0) return y;
  if (y == 0) return x;
  return gcd(y, x % y);
}
bool prime[1000006];
void sieve(int n) {
  for (long long i = 0; i < n + 1; i++) prime[i] = 1;
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  prime[1] = prime[0] = 0;
}
long long n, m, k, q, Q, T, l, r, x, y, z;
long long a[500005];
long long b[500005];
string second, t;
long long ans = 0;
int mat[121][5];
double cnt[5];
double eps = 1e-10;
int get(double x) {
  double d = 0.5;
  if (x > d + eps) return 500;
  if (x > d / 2 + eps) return 1000;
  if (x > d / 4 + eps) return 1500;
  if (x > d / 8 + eps) return 2000;
  if (x > d / 16 + eps) return 2500;
  return 3000;
}
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  };
  cin >> n;
  for (long long i = 0; i < n; i++)
    for (int ele = 0; ele < 5; ele++) cin >> mat[i][ele];
  ;
  memset(cnt, 0, sizeof(cnt));
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 5; j++) {
      if (mat[i][j] != -1) ++cnt[j];
    }
  }
  for (long long bots = 0; bots < 1e4; bots++) {
    int vscore = 0, pscore = 0;
    double tot = n + bots;
    for (long long j = 0; j < 5; j++) {
      if (mat[0][j] == -1) {
        int pts = get(cnt[j] / tot);
        if (mat[1][j] != -1) pscore += pts - pts * mat[1][j] / 250;
      } else if (mat[1][j] == -1 || mat[0][j] <= mat[1][j]) {
        int pts = get(cnt[j] / tot);
        vscore += pts - pts * mat[0][j] / 250;
        if (mat[1][j] != -1) pscore += pts - pts * mat[1][j] / 250;
      } else {
        int pts = get((cnt[j] + bots) / tot);
        vscore += pts - pts * mat[0][j] / 250;
        if (mat[1][j] != -1) pscore += pts - pts * mat[1][j] / 250;
      }
    }
    if (vscore > pscore) {
      cout << bots << endl;
      exit(0);
    }
  }
  cout << -1 << endl;
}
