#include <bits/stdc++.h>
using namespace std;
long long n, x, arr[5] = {}, petya = 0, vasya = 0, scor[5], temparr[5],
                oldn = 0;
vector<vector<long long> > v(2);
bool check(long long mid) {
  petya = 0, vasya = 0, scor[0] = 0, scor[1] = 0, scor[2] = 0, scor[3] = 0,
  scor[4] = 0;
  for (int h = 0; h < 5; h++) {
    temparr[h] = arr[h];
    if (v[1][h] != -1 && v[0][h] != -1) {
      if (v[1][h] <= v[0][h]) {
        temparr[h] += mid;
      }
    }
  }
  mid = (n + mid);
  for (int h = 0; h < 5; h++) {
    long long numbersolve = temparr[h];
    if (numbersolve > mid / 2LL) {
      scor[h] = 500;
    } else if (numbersolve > mid / 4LL) {
      scor[h] = 1000;
    } else if (numbersolve > mid / 8LL) {
      scor[h] = 1500;
    } else if (numbersolve > mid / 16LL) {
      scor[h] = 2000;
    } else if (numbersolve > mid / 32LL) {
      scor[h] = 2500;
    } else
      scor[h] = 3000;
    if (v[0][h] != -1) {
      vasya += scor[h] - (v[0][h] * scor[h]) / 250LL;
    }
    if (v[1][h] != -1) {
      petya += scor[h] - (v[1][h] * scor[h]) / 250LL;
    }
  }
  if (vasya > petya) {
    return 1;
  }
  return 0;
}
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cin >> n;
  oldn = n;
  for (int i = 0; i < n; i++) {
    for (int h = 0; h < 5; h++) {
      cin >> x;
      if (i < 2) v[i].push_back(x);
      if (x != -1) {
        arr[h]++;
      }
    }
  }
  n = oldn;
  long long st = 0, en = 2000000007;
  for (int i = 0; i < 1e6; i++) {
    if (check(i)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
