#include <bits/stdc++.h>
using namespace std;
int get(double p, int q) {
  if (p / q <= 1.0 / 32) return 3000;
  if (p / q <= 1.0 / 16) return 2500;
  if (p / q <= 1.0 / 8) return 2000;
  if (p / q <= 1.0 / 4) return 1500;
  if (p / q <= 1.0 / 2) return 1000;
  return 500;
}
const int N = 120;
int n, a[N][5], solved[5];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5; j++) {
      scanf("%d", &a[i][j]);
      if (a[i][j] != -1) {
        solved[j]++;
      }
    }
  }
  for (int bots = 0; bots <= 1e6; bots++) {
    int f = 0, s = 0;
    for (int j = 0; j < 5; j++) {
      int total = n + bots;
      if (a[0][j] != -1) {
        f += get(solved[j], total) * (1 - a[0][j] / 250.0);
      }
      if (a[1][j] != -1) {
        s += get(solved[j], total) * (1 - a[1][j] / 250.0);
      }
    }
    if (f > s) {
      cout << bots;
      return 0;
    }
    for (int j = 0; j < 5; j++) {
      if (a[0][j] != -1 && a[1][j] != -1 && a[0][j] > a[1][j]) {
        solved[j]++;
      }
    }
  }
  cout << -1;
  return 0;
}
