#include <bits/stdc++.h>
using namespace std;
int a[122][10];
int ans[11000];
int cnts[10], cntn[10];
int n;
int check(int x) {
  long long sum1 = 0, sum2 = 0;
  for (int j = 1; j <= 5; j++) {
    if (a[1][j] == -1) {
      long long so = 0;
      if (a[2][j] == -1) continue;
      double per = (double)(cnts[j]) / (n + x);
      if (per > 0.5)
        so = 500;
      else if (per > 0.25)
        so = 1000;
      else if (per > 0.125)
        so = 1500;
      else if (per > 1.0 / 16)
        so = 2000;
      else if (per > 1.0 / 32)
        so = 2500;
      else if (per >= 0)
        so = 3000;
      sum2 += so / 250 * (250 - a[2][j]);
    } else {
      if (a[1][j] < a[2][j] || a[2][j] == -1) {
        double per = (double)(cnts[j]) / (n + x);
        long long so = 0;
        if (per > 0.5)
          so = 500;
        else if (per > 0.25)
          so = 1000;
        else if (per > 0.125)
          so = 1500;
        else if (per > 1.0 / 16)
          so = 2000;
        else if (per > 1.0 / 32)
          so = 2500;
        else if (per >= 0)
          so = 3000;
        sum1 += so / 250 * (250 - a[1][j]);
        if (a[2][j] != -1) sum2 += so / 250 * (250 - a[2][j]);
      } else {
        double per = (double)(cnts[j] + x) / (n + x);
        long long so = 0;
        if (per > 0.5)
          so = 500;
        else if (per > 0.25)
          so = 1000;
        else if (per > 0.125)
          so = 1500;
        else if (per > 1.0 / 16)
          so = 2000;
        else if (per > 1.0 / 32)
          so = 2500;
        else if (per >= 0)
          so = 3000;
        sum1 += so / 250 * (250 - a[1][j]);
        if (a[2][j] != -1) sum2 += so / 250 * (250 - a[2][j]);
      }
    }
  }
  return sum1 > sum2;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 5; j++) scanf("%d", &a[i][j]);
  for (int j = 1; j <= 5; j++)
    for (int i = 1; i <= n; i++) {
      if (a[i][j] != -1) cnts[j]++;
      cntn[j]++;
    }
  int pos = 0;
  for (int j = 1; j <= 5; j++) {
    int sum1 = cnts[j];
    for (int i = 1; i <= 5; i++) {
      sum1 *= 2;
      if (sum1 > cntn[j]) ans[++pos] = sum1 - cntn[j];
    }
  }
  ans[++pos] = 0;
  sort(ans + 1, ans + 1 + pos);
  for (int i = 1; i <= pos; i++) {
    if (check(ans[i])) {
      printf("%d\n", ans[i]);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
