#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v;
int s[5], n, l[5], pt;
double r[5];
bool chk(int num) {
  for (int j = 0; j < 5; j++) {
    if (l[j] == 0) {
      r[j] = (s[j] + num + 0.0) / (n + num);
    } else {
      r[j] = (s[j] + 0.0) / (n + num);
    }
  }
  int score = 0, num1, num2;
  for (int i = 0; i < 5; i++) {
    pt = v[1][i] - v[0][i];
    if (v[0][i] == -1 && pt != 0) pt = (250 - v[1][i]) * -1;
    if (v[1][i] == -1 && pt != 0) pt = (250 - v[0][i]);
    if (r[i] <= 1.0 / 32)
      pt = pt * 12;
    else if (r[i] <= 1.0 / 16)
      pt = pt * 10;
    else if (r[i] <= 1.0 / 8)
      pt = pt * 8;
    else if (r[i] <= 1.0 / 4)
      pt = pt * 6;
    else if (r[i] <= 1.0 / 2)
      pt = pt * 4;
    else
      pt = pt * 2;
    score += pt;
  }
  if (score > 0)
    return 1;
  else
    return 0;
}
int main() {
  int num;
  memset(s, 0, sizeof(s));
  cin >> n;
  for (int i = 0; i < n; i++) {
    vector<int> a;
    for (int j = 0; j < 5; j++) {
      cin >> num;
      if (num != -1) s[j] += 1;
      a.push_back(num);
    }
    v.push_back(a);
  }
  for (int j = 0; j < 5; j++) {
    if (v[0][j] == -1 && v[1][j] != -1) l[j] = 0;
    if (v[1][j] == -1 && v[0][j] != -1)
      l[j] = 1;
    else
      l[j] = (v[0][j] < v[1][j]);
  }
  num = 32 * n;
  for (int i = 0; i < num; i++) {
    if (chk(i)) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
