#include <bits/stdc++.h>
using namespace std;
int x1[5], x2[5];
int points1[5], points2[5];
int ACSubmit[5] = {0, 0, 0, 0, 0};
bool solved1[5], solved2[5], cheat[5], flag = false;
int n, i, j, quest[5];
double fraction;
int ans, temp;
int MPV(int id) {
  fraction = (double)ACSubmit[id] / n;
  if (fraction > 1.0 / 2) return 2;
  if (fraction > 1.0 / 4) return 4;
  if (fraction > 1.0 / 8) return 6;
  if (fraction > 1.0 / 16) return 8;
  if (fraction > 1.0 / 32) return 10;
  return 12;
}
int score1() {
  temp = 0;
  for (j = 0; j < 5; j++) {
    temp += MPV(j) * points1[j];
  }
  return temp;
}
int score2() {
  temp = 0;
  for (j = 0; j < 5; j++) {
    temp += MPV(j) * points2[j];
  }
  return temp;
}
int main() {
  scanf("%d", &n);
  scanf("%d%d%d%d%d", &x1[0], &x1[1], &x1[2], &x1[3], &x1[4]);
  for (j = 0; j < 5; j++) {
    if (x1[j] != -1) {
      ACSubmit[j]++;
      points1[j] = 250 - x1[j];
      solved1[j] = true;
    } else {
      points1[j] = 0;
      solved1[j] = false;
    }
  }
  scanf("%d%d%d%d%d", &x2[0], &x2[1], &x2[2], &x2[3], &x2[4]);
  for (j = 0; j < 5; j++) {
    if (x2[j] != -1) {
      ACSubmit[j]++;
      points2[j] = 250 - x2[j];
      solved2[j] = true;
    } else {
      points2[j] = 0;
      solved2[j] = false;
    }
  }
  for (i = 2; i < n; i++) {
    scanf("%d%d%d%d%d", &quest[0], &quest[1], &quest[2], &quest[3], &quest[4]);
    for (j = 0; j < 5; j++) {
      if (quest[j] != -1) ACSubmit[j]++;
    }
  }
  for (j = 0; j < 5; j++) {
    if (!solved1[j])
      cheat[j] = false;
    else {
      flag = true;
      if (!solved2[j])
        cheat[j] = false;
      else {
        if (x1[j] >= x2[j])
          cheat[j] = true;
        else
          cheat[j] = false;
      }
    }
  }
  if (score1() > score2())
    ans = 0;
  else {
    ans = -1;
    if (flag) {
      for (i = 1; i <= 100000; i++) {
        n++;
        for (j = 0; j < 5; j++)
          if (cheat[j]) ACSubmit[j]++;
        if (score1() > score2()) {
          ans = i;
          break;
        }
      }
    }
  }
  printf("%d", ans);
  return 0;
}
