#include <bits/stdc++.h>
using namespace std;
int Sub[2][5];
int S[5];
pair<int, int> Ord[5];
int MP(float per) {
  if (per <= 1)
    return 3000;
  else if (per <= 2)
    return 2500;
  else if (per <= 4)
    return 2000;
  else if (per <= 8)
    return 1500;
  else if (per <= 16)
    return 1000;
  else
    return 500;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  cin.get();
  int a1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5; j++) {
      cin >> a1;
      if (a1 != -1) S[j]++;
      if (i <= 1) Sub[i][j] = a1;
    }
  }
  for (int j = 0; j < 5; j++) {
    if (Sub[0][j] != -1 && Sub[1][j] != -1)
      Ord[j] = {j, Sub[1][j] - Sub[0][j]};
    else if (Sub[0][j] == -1) {
      if (Sub[1][j] == -1)
        Ord[j] = {j, 0};
      else
        Ord[j] = {j, -100};
    } else
      Ord[j] = {j, 100};
  }
  int L = 0, R = 1e9 + 8, Max = 1e9 + 8;
  for (int M = 0; M < 180 * 64; M++) {
    int Sor, A = 0, B = 0;
    for (int i = 0; i < 5; i++) {
      int No = Ord[i].first;
      if (Ord[i].second > 0) {
        float L = 32.0 * S[No] / (n + M);
        Sor = MP(L);
      } else if (Ord[i].second < 0) {
        float L;
        if (Sub[0][No] != -1)
          L = 32.0 * (S[No] + M) / (n + M);
        else
          L = 32.0 * S[No] / (n + M);
        Sor = MP(L);
      }
      if (Ord[i].second != 0) {
        if (Sub[0][No] != -1) A += Sor * (250 - Sub[0][No]) / 250;
        if (Sub[1][No] != -1) B += Sor * (250 - Sub[1][No]) / 250;
      }
    }
    if (A > B) {
      R = M;
      break;
    }
  }
  if (R != Max)
    cout << R;
  else
    cout << -1;
}
