#include <bits/stdc++.h>
using namespace std;
int p[5], a[5], b[5], n;
int score(double x) {
  if (x - 1.0 / 2 > 1e-9) return 500;
  if (x - 1.0 / 4 > 1e-9) return 1000;
  if (x - 1.0 / 8 > 1e-9) return 1500;
  if (x - 1.0 / 16 > 1e-9) return 2000;
  if (x - 1.0 / 32 > 1e-9) return 2500;
  return 3000;
}
bool check(int mid) {
  int s1 = 0, s2 = 0, c, d;
  for (int i = 0; i < 5; i++) {
    if (a[i] == -1 && b[i] == -1) continue;
    d = score((p[i]) * 1.0 / (n + mid));
    if (a[i] > -1)
      c = score((p[i] + mid) * 1.0 / (n + mid));
    else
      c = d;
    if (b[i] == -1 || a[i] < b[i] && a[i] != -1) {
      s1 += d - d / 250 * a[i];
      if (b[i] != -1) s2 += d - d / 250 * b[i];
    } else {
      s2 += c - c / 250 * b[i];
      if (a[i] != -1) s1 += c - c / 250 * a[i];
    }
  }
  return s1 > s2;
}
int main() {
  scanf("%d", &n);
  scanf("%d%d%d%d%d", &a[0], &a[1], &a[2], &a[3], &a[4]);
  scanf("%d%d%d%d%d", &b[0], &b[1], &b[2], &b[3], &b[4]);
  for (int i = 0; i < 5; i++) {
    if (a[i] > -1) p[i]++;
    if (b[i] > -1) p[i]++;
  }
  for (int i = 2; i < n; i++) {
    for (int i = 0; i < 5; i++) {
      int x;
      scanf("%d", &x);
      if (x > -1) p[i]++;
    }
  }
  int i;
  for (i = 0; i < 10000; i++)
    if (check(i)) break;
  if (i == 10000)
    printf("-1\n");
  else
    printf("%d\n", i);
  return 0;
}
