#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using ld = long double;
using pii = pair<int, int>;
ll val(ll solve, ll whole) {
  if (2 * solve > whole) return 500;
  if (4 * solve > whole) return 1000;
  if (8 * solve > whole) return 1500;
  if (16 * solve > whole) return 2000;
  if (32 * solve > whole) return 2500;
  return 3000;
}
ll score(vi &t, vector<ll> &cnt, ll whole) {
  ll ans = 0;
  for (int i = 0; i < t.size(); i++)
    if (t[i] != -1) ans += val(cnt[i], whole) * (250 - t[i]);
  return ans;
}
bool go(vector<vi> &a, ll k, int mask) {
  vector<ll> cnt(a[0].size());
  for (int i = 0; i < a.size(); i++)
    for (int j = 0; j < a[i].size(); j++)
      if (a[i][j] != -1) cnt[j]++;
  for (int i = 0; i < 5; i++)
    if ((mask & (1 << i)) && a[0][i] != -1) cnt[i] += k;
  ll whole = a.size() + (mask == 0 ? 0 : k);
  return score(a[0], cnt, whole) > score(a[1], cnt, whole);
}
void solve() {
  int n;
  cin >> n;
  vector<vi> a(n, vi(5));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 5; j++) cin >> a[i][j];
  for (int k = 0; k < 32 * n; k++)
    for (int mask = 1; mask < 1 << 5; mask++)
      if (go(a, k, mask)) {
        cout << k << '\n';
        return;
      }
  cout << -1 << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
