#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > score(122, vector<int>(5, 0));
vector<int> pass(5, 0);
inline int cost(double d) {
  int res = 0;
  double t = 1.;
  while (res < 3000) {
    if (d > t) {
      return res;
    } else {
      t /= 2.0;
      res += 500;
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(10);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 5; ++j) {
      cin >> score[i][j];
      if (score[i][j] != -1) {
        ++pass[j];
      }
    }
  }
  for (int i = 0; i < 5000; ++i) {
    int t = 0;
    for (int j = 0; j < 5; ++j) {
      int mx = -1000010000;
      for (int k = 0; k < i + 1; ++k) {
        int scv = 0, scp = 0;
        double d = (1.0 * (k + pass[j])) / (i + n);
        int s = cost(d);
        if (score[0][j] != -1) {
          scv += s - (s * score[0][j] / 250);
        }
        if (score[1][j] != -1) {
          scp += s - (s * score[1][j] / 250);
        }
        mx = max(mx, scv - scp);
        if (score[0][j] == -1) {
          break;
        }
      }
      t += mx;
    }
    if (t > 0) {
      std::cout << i;
      return 0;
    };
  }
  cout << -1;
  return 0;
}
