#include <bits/stdc++.h>
using namespace std;
int n, a[125][5], ans, cnt[5];
int key(double x) {
  if (x < 1.0 / 32 + 1e-10)
    return 6;
  else if (x < 1.0 / 16 + 1e-10)
    return 5;
  else if (x < 1.0 / 8 + 1e-10)
    return 4;
  else if (x < 1.0 / 4 + 1e-10)
    return 3;
  else if (x < 1.0 / 2 + 1e-10)
    return 2;
  else
    return 1;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 5; ++j) {
      scanf("%d", &a[i][j]);
      if (a[i][j] > -1) cnt[j]++;
    }
  }
  int tcnt[5];
  for (int mi = 0; mi < 120 * 32; ++mi) {
    memset(tcnt, 0, sizeof(tcnt));
    for (int j = 0; j < 5; ++j) {
      if (a[1][j] != -1 && a[2][j] != -1) {
        if (a[1][j] > a[2][j]) tcnt[j] = mi;
      }
    }
    double s[3];
    s[2] = s[1] = 0.0;
    for (int i = 1; i < 3; ++i) {
      for (int j = 0; j < 5; ++j) {
        if (a[i][j] != -1) {
          double tx = 1.0 * (cnt[j] + tcnt[j]) / (n + mi);
          s[i] += 1.0 * key(tx) * (1.0 - 1.0 * a[i][j] / 250);
        }
      }
    }
    if (s[1] > s[2] + 1e-10) {
      printf("%d\n", mi);
      return 0;
    }
  }
  printf("-1");
  return 0;
}
