#include <bits/stdc++.h>
long long n;
long long solved[5] = {}, a[5], b[5];
int score(long long time, long long solved, long long participated) {
  int maxScore = (solved * 2 > participated)    ? 500
                 : (solved * 4 > participated)  ? 1000
                 : (solved * 8 > participated)  ? 1500
                 : (solved * 16 > participated) ? 2000
                 : (solved * 32 > participated) ? 2500
                                                : 3000;
  return (time != -1) ? maxScore - time * maxScore / 250 : 0;
}
bool check(long long M) {
  long long scoreA = 0, scoreB = 0;
  for (int i = 0; i < 5; ++i) {
    long long s = solved[i];
    if (a[i] != -1 && b[i] != -1 && a[i] > b[i]) s += M;
    scoreA += score(a[i], s, n + M);
    scoreB += score(b[i], s, n + M);
  }
  return scoreA > scoreB;
}
void solution() {
  scanf("%I64d", &n);
  for (int j = 0; j < 2; ++j)
    for (int i = 0; i < 5; ++i) {
      scanf("%I64d", (j ? b : a) + i);
      if ((j ? b : a)[i] != -1) ++solved[i];
    }
  for (int j = 2; j < n; ++j)
    for (int i = 0, tmp; i < 5; ++i) {
      scanf("%I64d", &tmp);
      if (tmp != -1) ++solved[i];
    }
  long long L = -1, R = 4000;
  while (L < R)
    if (check(++L)) break;
  printf("%I64d", check(L) ? L : check(R) ? R : -1);
}
int main() {
  solution();
  return 0;
}
