#include <bits/stdc++.h>
using namespace std;
int k, p = 250001;
int r[6], p1[6], p2[6], n;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < 5; i++) {
    scanf("%d", &p1[i]);
    if (p1[i] != -1) r[i]++;
  }
  for (int i = 0; i < 5; i++) {
    scanf("%d", &p2[i]);
    if (p2[i] != -1) r[i]++;
  }
  for (int i = 2; i < n; i++) {
    for (int i = 0; i < 5; i++) {
      scanf("%d", &k);
      if (k != -1) r[i]++;
    }
  }
  int k, num1 = 0, num2 = 0;
  for (k = 0; k <= p; k++) {
    num1 = 0, num2 = 0;
    int l;
    for (int i = 0; i < 5; i++) {
      if ((p1[i] == -1 && p2[i] != -1)) {
        if ((r[i]) * 2 > n + k)
          l = 500;
        else if ((r[i]) * 4 > n + k)
          l = 1000;
        else if ((r[i]) * 8 > n + k)
          l = 1500;
        else if ((r[i]) * 16 > n + k)
          l = 2000;
        else if ((r[i]) * 32 > n + k)
          l = 2500;
        else
          l = 3000;
        num2 += (l * (250 - p2[i])) / 250;
      }
      if ((p1[i] != -1 && p2[i] == -1)) {
        if ((r[i]) * 2 > n + k)
          l = 500;
        else if ((r[i]) * 4 > n + k)
          l = 1000;
        else if ((r[i]) * 8 > n + k)
          l = 1500;
        else if ((r[i]) * 16 > n + k)
          l = 2000;
        else if ((r[i]) * 32 > n + k)
          l = 2500;
        else
          l = 3000;
        num1 += (l * (250 - p1[i])) / 250;
      }
      if ((p1[i] != -1 && p2[i] != -1 && p1[i] > p2[i])) {
        if ((k + r[i]) * 2 > n + k)
          l = 500;
        else if ((k + r[i]) * 4 > n + k)
          l = 1000;
        else if ((k + r[i]) * 8 > n + k)
          l = 1500;
        else if ((k + r[i]) * 16 > n + k)
          l = 2000;
        else if ((k + r[i]) * 32 > n + k)
          l = 2500;
        else
          l = 3000;
        num1 += (l * (250 - p1[i])) / 250;
        num2 += (l * (250 - p2[i])) / 250;
      }
      if ((p1[i] != -1 && p2[i] != -1 && p1[i] < p2[i])) {
        if ((r[i]) * 2 > n + k)
          l = 500;
        else if ((r[i]) * 4 > n + k)
          l = 1000;
        else if ((r[i]) * 8 > n + k)
          l = 1500;
        else if ((r[i]) * 16 > n + k)
          l = 2000;
        else if ((r[i]) * 32 > n + k)
          l = 2500;
        else
          l = 3000;
        num1 += (l * (250 - p1[i])) / 250;
        num2 += (l * (250 - p2[i])) / 250;
      }
    }
    if (num1 > num2) break;
  }
  if (k == 250002)
    printf("-1\n");
  else
    printf("%d\n", k);
}
