#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1000000000")
using namespace std;
const int maxn = 200;
int v[maxn][5];
int cnt[5];
long long getr(int pos, long long cn, long long n, int i) {
  if (v[i][pos] == -1) {
    return 0;
  }
  if (2 * cn > n) {
    return (long long)500 * (250 - v[i][pos]);
  }
  if (4 * cn > n) {
    return (long long)1000 * (250 - v[i][pos]);
  }
  if (8 * cn > n) {
    return (long long)1500 * (250 - v[i][pos]);
  }
  if (16 * cn > n) {
    return (long long)2000 * (250 - v[i][pos]);
  }
  if (32 * cn > n) {
    return (long long)2500 * (250 - v[i][pos]);
  }
  return (long long)3000 * (250 - v[i][pos]);
}
long long go(int pos, long long cn, long long n) {
  return getr(pos, cn, n, 0) - getr(pos, cn, n, 1);
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5; j++) {
      scanf("%d", &v[i][j]);
      if (v[i][j] != -1) {
        cnt[j]++;
      }
    }
  }
  for (int m = 0; m <= (int)1e5 + 10; m++) {
    long long del = 0;
    for (int i = 0; i < 5; i++) {
      long long cn = cnt[i];
      long long z = go(i, cn, n + m);
      if (v[0][i] != -1) {
        z = max(z, go(i, cn + m, n + m));
      }
      del += z;
    }
    if (del > 0) {
      cout << m << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
