#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[127][7];
long long ok[7];
long long score(long long a, long long b) {
  if (2 * a > b) return 500;
  if (4 * a > b) return 1000;
  if (8 * a > b) return 1500;
  if (16 * a > b) return 2000;
  if (32 * a > b) return 2500;
  return 3000;
}
bool check(long long k) {
  long long vs = 0, ps = 0;
  for (long long i = 1; i <= 5; ++i) {
    if (a[1][i] == -1 && a[2][i] == -1) continue;
    if (a[1][i] == -1) {
      if (a[1][i] != -1)
        vs += score(ok[i], n + k) - score(ok[i], n + k) / 250 * a[1][i];
      if (a[2][i] != -1)
        ps += score(ok[i], n + k) - score(ok[i], n + k) / 250 * a[2][i];
      continue;
    }
    if (a[2][i] == -1) {
      if (a[1][i] != -1)
        vs += score(ok[i], n + k) - score(ok[i], n + k) / 250 * a[1][i];
      if (a[2][i] != -1)
        ps += score(ok[i], n + k) - score(ok[i], n + k) / 250 * a[2][i];
      continue;
    }
    if (a[1][i] > a[2][i]) {
      if (a[1][i] != -1)
        vs += score(ok[i] + k, n + k) - score(ok[i] + k, n + k) / 250 * a[1][i];
      if (a[2][i] != -1)
        ps += score(ok[i] + k, n + k) - score(ok[i] + k, n + k) / 250 * a[2][i];
    } else {
      if (a[1][i] != -1)
        vs += score(ok[i], n + k) - score(ok[i], n + k) / 250 * a[1][i];
      if (a[2][i] != -1)
        ps += score(ok[i], n + k) - score(ok[i], n + k) / 250 * a[2][i];
    }
  }
  return vs > ps;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  for (long long i = 1; i <= n; ++i) {
    for (long long j = 1; j <= 5; ++j) {
      cin >> a[i][j];
      if (a[i][j] != -1) ++ok[j];
    }
  }
  for (long long i = 0; i < 100000; ++i) {
    if (check(i)) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
