#include <bits/stdc++.h>
using namespace std;
int arr[121][6];
float s[6];
float ns[6];
bool b[6];
int maxpv[6];
int n;
int maxp(float r) {
  if (r > 0.5)
    return 2;
  else if (r > 0.25)
    return 4;
  else if (r > 0.125)
    return 6;
  else if (r > 0.0625)
    return 8;
  else if (r > 0.03125)
    return 10;
  else
    return 12;
}
bool calcu() {
  for (int i = 1; i <= 5; i++) {
    maxpv[i] = maxp(s[i] / (s[i] + ns[i]));
  }
  int ansa = 0;
  int ansb = 0;
  for (int i = 1; i <= 5; i++) {
    if (arr[1][i] != -1) ansa += maxpv[i] * (250 - arr[1][i]);
    if (arr[2][i] != -1) ansb += maxpv[i] * (250 - arr[2][i]);
  }
  if (ansa > ansb)
    return 1;
  else
    return 0;
}
int main() {
  scanf("%d", &n);
  memset(s, sizeof s, 0);
  memset(ns, sizeof ns, 0);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 5; j++) {
      scanf("%d", &arr[i][j]);
      if (arr[i][j] != -1)
        s[j]++;
      else
        ns[j]++;
    }
  }
  for (int i = 1; i <= 5; i++) {
    if (arr[1][i] != -1 && arr[2][i] != -1)
      b[i] = arr[1][i] > arr[2][i];
    else
      b[i] = false;
  }
  int k = 0;
  while (!calcu() && k < 10000) {
    for (int i = 1; i <= 5; i++)
      if (b[i])
        s[i]++;
      else
        ns[i]++;
    k++;
  }
  if (calcu())
    printf("%d\n", k);
  else
    printf("-1\n");
  return 0;
}
