#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int g(int a, int b) {
  if (2 * a > b) return 1;
  if (4 * a > b) return 2;
  if (8 * a > b) return 3;
  if (16 * a > b) return 4;
  if (32 * a > b) return 5;
  return 6;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, fi, se, tmp;
  cin >> n;
  vector<int> a(5), b(5), cheat(5), solved(5, 0);
  for (int i = 0; i < 5; ++i) cin >> a[i];
  for (int i = 0; i < 5; ++i) cin >> b[i];
  for (int i = 0; i < 5; ++i) {
    if (a[i] == -1)
      a[i] = 0;
    else
      a[i] = 250 - a[i];
    if (b[i] == -1)
      b[i] = 0;
    else
      b[i] = 250 - b[i];
    if (a[i] > b[i] || a[i] == 0)
      cheat[i] = 0;
    else
      cheat[i] = 1;
    if (a[i] > 0) solved[i]++;
    if (b[i] > 0) solved[i]++;
  }
  for (int i = 2; i < n; ++i) {
    for (int j = 0; j < 5; ++j) {
      cin >> tmp;
      if (tmp >= 0) solved[j]++;
    }
  }
  for (int i = 0; i < 4000; ++i) {
    fi = se = 0;
    for (int j = 0; j < 5; ++j) {
      fi += a[j] * g(solved[j], n + i);
      se += b[j] * g(solved[j], n + i);
    }
    if (fi > se) {
      cout << i << endl;
      return 0;
    }
    for (int j = 0; j < 5; ++j) {
      if (cheat[j]) solved[j]++;
    }
  }
  cout << -1 << endl;
  return 0;
}
