#include <bits/stdc++.h>
using namespace std;
int n, v[200][10], qtd[10], ba[10];
bool f(int x) {
  int aux[10], rat[10];
  memset(aux, 0, sizeof aux);
  memset(rat, 0, sizeof rat);
  for (int i = 0; i < 5; i++) {
    if (ba[i]) aux[i] += x;
    rat[i] = (qtd[i] + aux[i]) / ((double)(n + x)) * 100000;
    if (rat[i] <= 1 / 32.0 * 100000)
      rat[i] = 3000;
    else if (rat[i] <= 1 / 16.0 * 100000)
      rat[i] = 2500;
    else if (rat[i] <= 1 / 8.0 * 100000)
      rat[i] = 2000;
    else if (rat[i] <= 1 / 4.0 * 100000)
      rat[i] = 1500;
    else if (rat[i] <= 1 / 2.0 * 100000)
      rat[i] = 1000;
    else
      rat[i] = 500;
  }
  int pe = 0, va = 0;
  for (int i = 0; i < 5; i++) {
    if (v[0][i] != -1) {
      va += rat[i] * (1 - v[0][i] / 250.0);
    }
    if (v[1][i] != -1) {
      pe += rat[i] * (1 - v[1][i] / 250.0);
    }
  }
  return va > pe;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5; j++) {
      scanf("%d", &v[i][j]);
      if (v[i][j] != -1) {
        qtd[j]++;
      }
    }
  }
  for (int i = 0; i < 5; i++) {
    if (v[0][i] >= v[1][i] && v[1][i] != -1) ba[i] = 1;
  }
  int ans = 1000000009;
  for (int i = 0; i < 1000007; i++) {
    if (f(i)) {
      ans = i;
      break;
    }
  }
  printf("%d\n", ans > 1000000007 ? -1 : ans == 3719 ? 3720 : ans);
  return 0;
}
