#include <bits/stdc++.h>
using namespace std;
int r(double ra) {
  if (ra > 0.5) {
    return 500;
  } else if (ra > 0.25) {
    return 1000;
  } else if (ra > 0.125) {
    return 1500;
  } else if (ra > 0.0625) {
    return 2000;
  } else if (ra > 0.03125) {
    return 2500;
  } else {
    return 3000;
  }
}
int main() {
  int n, i, j, a[124][5], yes[5], ans[5] = {0}, scorea, scoreb, rating;
  cin >> n;
  for (i = 0; i < n; i++) {
    for (j = 0; j < 5; j++) {
      cin >> a[i][j];
      if (a[i][j] == -1) {
        a[i][j] = 3600;
      }
    }
  }
  for (i = 0; i < 5; i++) {
    if (a[0][i] > a[1][i] and a[0][i] != 3600) {
      yes[i] = 1;
    } else {
      yes[i] = 0;
    }
  }
  for (i = 0; i < 5; i++) {
    for (j = 0; j < n; j++) {
      if (a[j][i] <= 176) {
        ans[i]++;
      }
    }
  }
  for (i = 0; i <= 32 * 120; i++) {
    scorea = 0;
    scoreb = 0;
    for (j = 0; j < 5; j++) {
      if (yes[j]) {
        double p = ((ans[j] + i) * 1.0 / (n + i) * 1.0) * 1.0;
        rating = r(p);
        rating = rating / 250;
        if (a[0][j] < 178) {
          scorea += (rating * (250 - a[0][j]));
        }
        if (a[1][j] < 178) {
          scoreb += (rating * (250 - a[1][j]));
        }
      } else {
        double p = ((ans[j]) * 1.0 / (n + i) * 1.0) * 1.0;
        rating = r(p);
        rating = rating / 250;
        if (a[0][j] < 178) {
          scorea += (rating * (250 - a[0][j]));
        }
        if (a[1][j] < 178) {
          scoreb += (rating * (250 - a[1][j]));
        }
      }
    }
    if (scorea > scoreb) {
      cout << i;
      return 0;
    }
  }
  cout << "-1";
}
