#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  int64_t n, tmp;
  cin >> n;
  vector<int64_t> arr(5, 0), a(5), b(5);
  for (int64_t i = 0; i < int64_t(n); ++i) {
    for (int64_t j = 0; j < int64_t(5); ++j) {
      cin >> tmp;
      arr[j] += (tmp != -1);
      if (i == 0) a[j] = tmp;
      if (i == 1) b[j] = tmp;
    }
  }
  for (int64_t i = 0; i <= 4000; i++) {
    double dif = 0;
    for (int64_t j = 0; j < 5; j++) {
      int64_t solvers, score;
      if (a[j] == -1 || b[j] == -1 || b[j] > a[j])
        solvers = arr[j];
      else
        solvers = arr[j] + i;
      double frac = solvers / (double)(n + i);
      if (frac <= 1) score = 500;
      if (frac <= 1 / 2.0) score = 1000;
      if (frac <= 1 / 4.0) score = 1500;
      if (frac <= 1 / 8.0) score = 2000;
      if (frac <= 1 / 16.0) score = 2500;
      if (frac <= 1 / 32.0) score = 3000;
      dif += (a[j] != -1 ? (1 - a[j] / 250.0) * score : 0) -
             (b[j] != -1 ? (1 - b[j] / 250.0) * score : 0);
    }
    if (dif > 0) return cout << i << endl, 0;
  }
  cout << -1 << endl;
  return 0;
}
