#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int a[150][150];
int cnt[10];
int jisuan(int id, int wang, int jishu, int n) {
  if (a[wang][id] == -1) return 0;
  int sum = 0;
  if (a[0][id] == -1 || a[1][id] == -1 || a[0][id] < a[1][id])
    sum = cnt[id];
  else
    sum = cnt[id] + jishu;
  int c = 500;
  for (int i = 2; i <= 32; i *= 2) {
    if (sum * i > n + jishu)
      break;
    else
      c = c + 500;
  }
  return c * (250 - a[wang][id]) / 250;
}
int main() {
  int n;
  while (~scanf("%d", &n)) {
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < n; i++)
      for (int j = 0; j < 5; j++) {
        scanf("%d", &a[i][j]);
        cnt[j] += (a[i][j] == -1 ? 0 : 1);
      }
    bool wang = false;
    for (int i = 0; i < 100000; i++) {
      if (wang) break;
      int sum1 = 0, sum2 = 0;
      for (int j = 0; j < 5; j++) {
        sum1 += jisuan(j, 0, i, n);
        sum2 += jisuan(j, 1, i, n);
      }
      if (sum1 > sum2) {
        printf("%d\n", i);
        wang = true;
      }
    }
    if (!wang) printf("-1\n");
  }
}
