#include <bits/stdc++.h>
using namespace std;
long long fd(long long a, long long b) {
  long long c = a / b;
  if (a % b != 0) c++;
  return c;
}
vector<vector<int> > table;
bool got1[5];
bool got2[5];
int cnt[5];
int bsubs = 999999999;
int n;
int get(int solve, int total) {
  double d = (double)solve / (double)total;
  if (0 <= d && d <= 1.0 / 32.0) return 3000;
  if (1.0 / 32.0 < d && d <= 1.0 / 16.0) return 2500;
  if (1.0 / 16.0 < d && d <= 1.0 / 8.0) return 2000;
  if (1.0 / 8.0 < d && d <= 1.0 / 4.0) return 1500;
  if (1.0 / 4.0 < d && d <= 1.0 / 2.0) return 1000;
  if (1.0 / 2.0 < d && d <= 1.0 / 1.0)
    return 500;
  else
    while (true)
      ;
}
bool can(int bots) {
  int tot = bots + n;
  for (int mask = 1; mask < (1 << 5); mask++) {
    int vscore = 0;
    int pscore = 0;
    for (int b = 0; b < 5; b++) {
      int maxi = 0;
      if ((mask & (1 << b)) && got1[b]) {
        maxi = get(bots + cnt[b], tot);
      } else {
        maxi = get(cnt[b], tot);
      }
      if (got1[b]) vscore += maxi - (maxi / 250) * table[0][b];
      if (got2[b]) pscore += maxi - (maxi / 250) * table[1][b];
    }
    if (vscore > pscore) {
      return true;
    }
  }
  return false;
}
int main() {
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    vector<int> v;
    for (int j = 0; j < (5); ++j) {
      int pr;
      cin >> pr;
      v.push_back(pr);
      if (i == 0 && pr != -1) got1[j] = true;
      if (i == 1 && pr != -1) got2[j] = true;
      if (pr != -1) cnt[j]++;
    }
    table.push_back(v);
  }
  int vsco = 0;
  int psco = 0;
  for (int i = 0; i < (5); ++i) {
    int tr = get(cnt[i], n);
    if (got1[i]) vsco += tr - (tr / 250) * table[0][i];
    if (got2[i]) psco += tr - (tr / 250) * table[1][i];
  }
  if (vsco > psco) {
    cout << 0 << endl;
    return 0;
  }
  int lo = 100000;
  int hi = 1000000000 + 10;
  for (int bots = 0; bots <= 100000; bots++) {
    if (can(bots)) {
      cout << bots << endl;
      return 0;
    }
  }
  while (lo < hi) {
    long long mid1 = ((long long)lo + (long long)hi) / 2;
    int mid = int(mid1);
    if (can(mid)) {
      hi = mid;
    } else {
      lo = mid + 1;
    }
  }
  if (lo > 1000000000 + 7) {
    cout << -1 << endl;
    return 0;
  }
  cout << lo << endl;
}
