#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10240000")
using namespace std;
int getAns(int n, int m, int solved) {
  if (solved * 2 > n)
    return 500 - 2 * m;
  else if (solved * 4 > n)
    return 1000 - 4 * m;
  else if (solved * 8 > n)
    return 1500 - 6 * m;
  else if (solved * 16 > n)
    return 2000 - 8 * m;
  else if (solved * 32 > n)
    return 2500 - 10 * m;
  else
    return 3000 - 12 * m;
}
int ans(const vector<int>& p, int all, vector<int>& solved) {
  int r = 0;
  for (int i = 0; i < 5; ++i) {
    if (p[i] != -1) r += getAns(all, p[i], solved[i]);
  }
  return r;
}
bool ok(int m, vector<vector<int> >& v, vector<int>& cnt) {
  int ans1 = 0;
  vector<int> solved(5, 0);
  for (int i = 0; i < 5; ++i) solved[i] = cnt[i];
  for (int i = 0; i < 5; ++i) {
    if (v[0][i] != -1) {
      if (v[1][i] == -1)
        ;
      else if (v[0][i] > v[1][i])
        solved[i] += m;
    }
  }
  if (ans(v[0], v.size() + m, solved) > ans(v[1], v.size() + m, solved))
    return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  int n;
  cin >> n;
  vector<vector<int> > v(n, vector<int>(5, -1));
  vector<int> cnt(5, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 5; ++j) {
      cin >> v[i][j];
      if (v[i][j] != -1) cnt[j]++;
    }
  }
  for (int i = 0; i <= 120 * 100; ++i)
    if (ok(i, v, cnt)) return cout << i, 0;
  cout << -1;
}
