#include <bits/stdc++.h>
using namespace std;
int a[1000][6], n, num[6];
long long score(long long x, long long y) {
  if (2 * x > y) return 500;
  if (4 * x > y) return 1000;
  if (x * 8 > y) return 1500;
  if (x * 16 > y) return 2000;
  if (x * 32 > y) return 2500;
  return 3000;
}
bool check(int now) {
  long long x = 0, y = 0;
  for (int i = 1; i <= 5; i++) {
    if (a[1][i] != -1) {
      if (a[1][i] < a[2][i] || a[2][i] == -1) {
        if (a[1][i] != -1) x += score(num[i], n + now) * (250 - a[1][i]);
        if (a[2][i] != -1) y += score(num[i], n + now) * (250 - a[2][i]);
      } else {
        if (a[1][i] != -1) x += score(now + num[i], n + now) * (250 - a[1][i]);
        if (a[2][i] != -1) y += score(now + num[i], n + now) * (250 - a[2][i]);
      }
    } else {
      if (a[2][i] != -1) y += score(num[i], n + now) * (250 - a[2][i]);
    }
  }
  return x > y;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 5; j++)
      scanf("%d", &a[i][j]), num[j] += (a[i][j] != -1);
  for (int i = 0; i <= 120 * 32; i++)
    if (check(i)) {
      cout << i << endl;
      return 0;
    }
  cout << -1;
  return 0;
}
