#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e9 + 1;
int a[201][201];
int cnt[10][10];
int calc(int x, int y) {
  if (x * 2 > y)
    return 500;
  else if (x * 4 > y)
    return 1000;
  else if (x * 8 > y)
    return 1500;
  else if (x * 16 > y)
    return 2000;
  else if (x * 32 > y)
    return 2500;
  else
    return 3000;
}
int use[10];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5; j++) {
      cin >> a[i][j];
    }
  }
  for (int k = 0; k < 5; k++) {
    if (a[0][k] == -1)
      use[k] = 0;
    else if (a[1][k] == -1 || (a[1][k] != -1 && a[1][k] > a[0][k]))
      use[k] = -1;
    else
      use[k] = 1;
  }
  for (int t = 0; t < 50000; t++) {
    int sc1 = 0, sc0 = 0;
    for (int i = 0; i < 5; i++) {
      long long x = 0, y = 0;
      for (int j = 0; j < n; j++) {
        if (a[j][i] != -1) x++;
      }
      if (use[i] == 1) x += t;
      y = n + t;
      if (a[0][i] != -1) {
        sc0 += calc(x, y) * (250 - a[0][i]);
      }
      if (a[1][i] != -1) {
        sc1 += calc(x, y) * (250 - a[1][i]);
      }
    }
    if (sc0 > sc1) {
      cout << t << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
