#include <bits/stdc++.h>
using namespace std;
const int maxntry = 120 * 32;
int getpo(int sum, int ac) {
  if (ac * 2 > sum) return 500;
  if (ac * 4 > sum) return 1000;
  if (ac * 8 > sum) return 1500;
  if (ac * 16 > sum) return 2000;
  if (ac * 32 > sum) return 2500;
  return 3000;
}
int calc(int po, int ti) {
  if (ti == -1) return 0;
  return po - po / 250 * ti;
}
int a[10], b[10], c[10];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  int n;
  cin >> n;
  for (int j = 1; j <= 5; ++j) {
    cin >> a[j];
    if (a[j] != -1) ++c[j];
  }
  for (int j = 1; j <= 5; ++j) {
    cin >> b[j];
    if (b[j] != -1) ++c[j];
  }
  for (int i = 3; i <= n; ++i) {
    for (int j = 1; j <= 5; ++j) {
      int x;
      cin >> x;
      if (x != -1) ++c[j];
    }
  }
  for (int j = 0; j <= maxntry; ++j) {
    int suma = 0, sumb = 0;
    for (int k = 1; k <= 5; ++k) {
      if (a[k] == -1 || (b[k] != -1 && b[k] <= a[k])) {
        int po;
        if (a[k] == -1)
          po = getpo(n + j, c[k]);
        else
          po = getpo(n + j, c[k] + j);
        suma += calc(po, a[k]);
        sumb += calc(po, b[k]);
      } else {
        int po = getpo(n + j, c[k]);
        suma += calc(po, a[k]);
        sumb += calc(po, b[k]);
      }
    }
    if (suma > sumb) {
      cout << j << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}
