#include <bits/stdc++.h>
void cheat();
int testscore(int a, int b);
using namespace std;
int n = 0;
int t[125][5];
int sc[125];
int va[5];
int robot[5];
int p[5];
int rb = 0;
int main(void) {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t[i][0] >> t[i][1] >> t[i][2] >> t[i][3] >> t[i][4];
  }
  cheat();
  cout << rb;
}
void cheat() {
  for (int j = 0; j < 5; j++) {
    p[j] = 0;
    for (int i = 0; i < n; i++) {
      if (t[i][j] != -1) p[j]++;
    }
    va[j] = testscore(p[j], n);
  }
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 5; j++) {
      if (t[i][j] != -1) sc[i] += (va[j] * (float)(1 - ((float)t[i][j] / 250)));
    }
  }
  for (int i = 0; i < 5; i++) {
    if ((t[0][i] <= t[1][i] && t[0][i] != -1) || t[1][i] == -1 || t[0][i] == -1)
      robot[i] = 0;
    else if (t[0][i] > t[1][i] && t[1][i] != -1) {
      robot[i] = 1;
    }
  }
  while (sc[0] <= sc[1]) {
    rb++;
    n++;
    for (int i = 0; i < 5; i++) {
      p[i] += robot[i];
      va[i] = testscore(p[i], n);
    }
    sc[1] = 0;
    sc[0] = 0;
    for (int i = 0; i < 5; i++) {
      if (t[1][i] != -1) sc[1] += va[i] * (float)(1 - ((float)t[1][i] / 250));
      if (t[0][i] != -1) sc[0] += va[i] * (float)(1 - ((float)t[0][i] / 250));
    }
    if (rb > 5000) {
      rb = -1;
      return;
    }
  }
  return;
}
int testscore(int a, int b) {
  if (2 * a > b)
    return 500;
  else if (4 * a > b)
    return 1000;
  else if (8 * a > b)
    return 1500;
  else if (16 * a > b)
    return 2000;
  else if (32 * a > b)
    return 2500;
  else
    return 3000;
}
