#include <bits/stdc++.h>
using namespace std;
int a[120][5];
int suc[5];
int get_dif(int l, int k, int j) {
  int type = 2 * l > k    ? 0
             : 4 * l > k  ? 1
             : 8 * l > k  ? 2
             : 16 * l > k ? 3
             : 32 * l > k ? 4
                          : 5;
  int dif = a[0][j] >= 0 ? (1 + type) * (500 - a[0][j] * 2) : 0;
  dif -= a[1][j] >= 0 ? (1 + type) * (500 - a[1][j] * 2) : 0;
  return dif;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 5; j++) {
      cin >> a[i][j];
      suc[j] += a[i][j] >= 0;
    }
  for (int need = 0; need <= n * 32; need++) {
    int sumdif = 0;
    for (int j = 0; j < 5; j++) {
      int dif = get_dif(suc[j], n + need, j);
      if (a[0][j] >= 0) dif = max(dif, get_dif(suc[j] + need, n + need, j));
      sumdif += dif;
    }
    if (sumdif > 0) {
      cout << need;
      return 0;
    }
  }
  cout << -1;
}
