#include <bits/stdc++.h>
using namespace std;
int V, P, n, t, a, b, s[5], v[5], p[5];
int Points(int s, int t) {
  if (s * 2 > t)
    return 500;
  else if (s * 4 > t)
    return 1000;
  else if (s * 8 > t)
    return 1500;
  else if (s * 16 > t)
    return 2000;
  else if (s * 32 > t)
    return 2500;
  else
    return 3000;
}
int Score(int p, int x) { return (double(p) * (double(1) - double(x) / 250)); }
void VP() {
  V = 0;
  P = 0;
  for (int j = 0; j < 5; j++) {
    V += Score(Points(s[j], t), v[j]) * (v[j] != -1);
    P += Score(Points(s[j], t), p[j]) * (p[j] != -1);
  }
}
int main() {
  cin >> n, t = n;
  for (int i = 0; i < t; i++) {
    for (int j = 0; j < 5; j++) {
      cin >> a;
      i == 0 ? v[j] = a : 0;
      i == 1 ? p[j] = a : 0;
      a != -1 ? s[j]++ : 0;
    }
  }
  for (int i = 0; i < 32 * n; i++) {
    for (int j = 0; j < 5; j++) {
      if (v[j] == p[j] && v[j] == -1)
        continue;
      else if (p[j] == -1)
        t = n + i;
      else if (v[j] == -1)
        continue;
      else {
        t = n + i;
        if (i && v[j] >= p[j]) s[j]++;
      }
    }
    VP();
    if (V > P) return cout << i, 0;
  }
  cout << -1 << endl;
}
