#include <bits/stdc++.h>
using namespace std;
struct P {
  int a[6];
} pp[100010];
int sum[6];
int cal(int ac, int all) {
  if (ac * 2 > all)
    return 500;
  else if (ac * 4 > all)
    return 1000;
  else if (ac * 8 > all)
    return 1500;
  else if (ac * 16 > all)
    return 2000;
  else if (ac * 32 > all)
    return 2500;
  else
    return 3000;
}
int n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i < (n + 1); i++) {
    for (int j = 1; j < (6); j++) {
      scanf("%d", &pp[i].a[j]);
      if (pp[i].a[j] != -1) sum[j]++;
    }
  }
  for (int i = 0; i < (5000); i++) {
    int all = i + n, sum1 = 0, sum2 = 0;
    for (int j = 1; j < (6); j++) {
      if (pp[1].a[j] != -1 && (pp[2].a[j] == -1 || pp[2].a[j] >= pp[1].a[j])) {
        int score = cal(sum[j], all);
        sum1 += score / 250 * (250 - pp[1].a[j]);
        if (pp[2].a[j] != -1) sum2 += score / 250 * (250 - pp[2].a[j]);
      } else if (pp[1].a[j] != -1 && pp[2].a[j] != -1 &&
                 pp[2].a[j] < pp[1].a[j]) {
        int score = cal(sum[j] + i, all);
        sum1 += score / 250 * (250 - pp[1].a[j]);
        sum2 += score / 250 * (250 - pp[2].a[j]);
      } else {
        int score = cal(sum[j], all);
        if (pp[2].a[j] != -1) sum2 += score / 250 * (250 - pp[2].a[j]);
      }
    }
    if (sum1 > sum2) {
      printf("%d\n", i);
      return 0;
    }
  }
  puts("-1");
}
