#include <bits/stdc++.h>
using namespace std;
int n;
int t[5][10], num[10];
int p[1000];
int f(int x, int y) {
  if ((long long)2 * x > y) return 500;
  if ((long long)4 * x > y) return 1000;
  if ((long long)8 * x > y) return 1500;
  if ((long long)16 * x > y) return 2000;
  if ((long long)32 * x > y) return 2500;
  return 3000;
}
bool check(int x) {
  int s = 0, sb = 0;
  for (int i = 1; i <= 5; i++) {
    if (t[1][i] < t[2][i] && t[1][i])
      s += f(num[i] + x, n + x) * (t[1][i] - t[2][i]);
    else
      s += f(num[i], n + x) * (t[1][i] - t[2][i]);
  }
  return s > 0;
}
int q[10] = {1, 2, 4, 8, 16, 32};
int main() {
  scanf("%d", &n);
  memset(num, 0, sizeof(num));
  for (int i = 1; i <= 2; i++)
    for (int j = 1; j <= 5; j++) {
      scanf("%d", &t[i][j]);
      if (t[i][j] == -1)
        t[i][j] = 0;
      else
        num[j]++, t[i][j] = 250 - t[i][j];
    }
  for (int i = 3; i <= n; i++)
    for (int j = 1; j <= 5; j++) {
      int x;
      scanf("%d", &x);
      if (x != -1) num[j]++;
    }
  int m = 0;
  for (int i = 1; i <= 5; i++) {
    for (int j = 1; j <= 5; j++) {
      if (t[1][i] < t[2][i] && t[1][i]) {
        p[++m] = (n - num[i] * q[j]) / (q[j] - 1) + 1;
        if (p[m] > 10000000007) m--;
      }
      if (t[1][i] > t[2][i]) {
        p[++m] = num[i] * q[j] - n;
        if (p[m] > 10000000007) m--;
      }
    }
  }
  p[++m] = 0;
  sort(p + 1, p + m + 1);
  for (int i = 1; i <= m; i++) {
    if (p[i] >= 0 && check(p[i])) {
      printf("%d\n", p[i]);
      return 0;
    }
  }
  printf("-1\n");
}
