#include <bits/stdc++.h>
using namespace std;
ifstream in("file.in");
ofstream out("file.out");
struct comp {
  bool operator()(long long a, long long b) { return a > b; }
};
int n, q[7][6], p[7][6], a[6], first[6], second[6], t, b[6], g = 1e9;
int main() {
  ios_base ::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= 5; i++) {
    cin >> first[i], first[i] = 250 - first[i];
    if (first[i] == 251)
      first[i] = 0;
    else
      a[i]++;
  }
  for (int i = 1; i <= 5; i++) {
    cin >> second[i], second[i] = 250 - second[i];
    if (second[i] == 251)
      second[i] = 0;
    else
      a[i]++;
  }
  for (int i = 3; i <= n; i++) {
    for (int j = 1; j <= 5; j++) {
      cin >> t;
      if (t > -1) a[j]++;
    }
  }
  t = 0;
  for (int j = 1; j <= 5; j++) {
    for (int k = 5; k >= 0; k--) {
      if (a[j] * (1 << k) <= n) {
        t += 2 * (k + 1) * (first[j] - second[j]);
        break;
      }
    }
  }
  if (t > 0) {
    cout << 0;
    return 0;
  }
  for (int i = 1; i <= 25000; i++) {
    n++;
    t = 0;
    for (int j = 1; j <= 5; j++) {
      if (first[j] < second[j] && first[j]) a[j]++;
      for (int k = 5; k >= 0; k--) {
        if (a[j] * (1 << k) <= n) {
          t += 2 * (k + 1) * (first[j] - second[j]);
          break;
        }
      }
    }
    if (t > 0) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
}
