#include <bits/stdc++.h>
using namespace std;
const int MX = 1000000007;
int n;
int tv[5];
int tp[5];
int cnt[5];
int getCost(int x) {
  if (n < 2 * x) return 500;
  if (n < 4 * x) return 1000;
  if (n < 8 * x) return 1500;
  if (n < 16 * x) return 2000;
  if (n < 32 * x) return 2500;
  return 3000;
}
int check(int a) {
  n += a;
  for (int i = 0; i < 5; i++)
    if (tv[i] >= tp[i] && tp[i] != -1 && tv[i] != -1) cnt[i] += a;
  int rv = 0;
  for (int i = 0; i < 5; i++)
    if (tv[i] != -1) rv += getCost(cnt[i]) * (250 - tv[i]) / 250;
  int rp = 0;
  for (int i = 0; i < 5; i++)
    if (tp[i] != -1) rp += getCost(cnt[i]) * (250 - tp[i]) / 250;
  for (int i = 0; i < 5; i++)
    if (tv[i] >= tp[i] && tp[i] != -1 && tv[i] != -1) cnt[i] -= a;
  n -= a;
  if (rv > rp) {
    return 1;
  } else {
    return 0;
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < 5; i++) {
    cin >> tv[i];
    if (tv[i] != -1) cnt[i]++;
  }
  for (int i = 0; i < 5; i++) {
    cin >> tp[i];
    if (tp[i] != -1) cnt[i]++;
  }
  int x;
  for (int i = 3; i <= n; i++) {
    for (int o = 0; o < 5; o++) {
      cin >> x;
      if (x != -1) cnt[o]++;
    }
  }
  int j = 0;
  while (!check(j) && j <= 10000) j++;
  if (j <= 10000)
    cout << j << endl;
  else
    cout << -1;
}
