#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;
double vas[10], pet[10];
int solve[10];
int pre1[10], pre2[10];
int trans(double x) {
  if (x > 1.0 / 2 && x <= 1) return 500;
  if (x <= 1.0 / 2 && x > 1.0 / 4) return 1000;
  if (x <= 1.0 / 4 && x > 1.0 / 8) return 1500;
  if (x <= 1.0 / 8 && x > 1.0 / 16) return 2000;
  if (x <= 1.0 / 16 && x > 1.0 / 32)
    return 2500;
  else
    return 3000;
}
int main() {
  int n;
  cin >> n;
  for (int j = 0; j < 5; j++) {
    scanf("%lf", &vas[j]);
    if (vas[j] != -1) solve[j]++;
  }
  for (int j = 0; j < 5; j++) {
    scanf("%lf", &pet[j]);
    if (pet[j] != -1) solve[j]++;
  }
  for (int i = 2; i < n; i++) {
    for (int j = 0; j < 5; j++) {
      int x;
      scanf("%d", &x);
      if (x != -1) solve[j]++;
    }
  }
  double sc1, sc2;
  for (int i = 0; i < 5; i++) {
    if (vas[i] != -1) {
      sc1 += trans((double)solve[i] / n) * (1.0 - (double)vas[i] / 250);
      pre1[i] = trans((double)solve[i] / n) * (1.0 - (double)vas[i] / 250);
    }
    if (pet[i] != -1) {
      sc2 += trans((double)solve[i] / n) * (1.0 - (double)pet[i] / 250);
      pre2[i] = trans((double)solve[i] / n) * (1.0 - (double)pet[i] / 250);
    }
  }
  for (int i = 0; i < n * 36; i++) {
    int tem1 = 0, tem2 = 0;
    for (int j = 0; j < 5; j++) {
      if (vas[j] != -1)
        tem1 +=
            trans((double)solve[j] / (n + i)) * (1.0 - (double)vas[j] / 250);
      if (pet[j] != -1)
        tem2 +=
            trans((double)solve[j] / (n + i)) * (1.0 - (double)pet[j] / 250);
      if (vas[j] > pet[j] && pet[j] != -1) solve[j]++;
    }
    if (tem1 > tem2) {
      printf("%d\n", i);
      return 0;
    }
  }
  puts("-1");
}
