#include <bits/stdc++.h>
using namespace std;
const int N = 5000;
const long long MOD = 1e9 + 7;
int n, sn[5] = {}, diff[5] = {};
vector<int> scores[2];
int find(int i) {
  int x = sn[i];
  if (2 * x > n) {
    return 500;
  }
  if (4 * x > n) {
    return 1000;
  }
  if (8 * x > n) {
    return 1500;
  }
  if (16 * x > n) {
    return 2000;
  }
  if (32 * x > n) {
    return 2500;
  }
  return 3000;
}
int sum() {
  int s = 0;
  for (int i = 0; i < 5; i++) {
    s += diff[i] * (find(i) / 250);
  }
  return s;
}
int main() {
  cin >> n;
  int x;
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 5; j++) {
      cin >> x;
      scores[i].push_back(x);
      if (x != -1) {
        sn[j]++;
      }
    }
  }
  for (int i = 2; i < n; i++) {
    for (int j = 0; j < 5; j++) {
      cin >> x;
      if (x != -1) {
        sn[j]++;
      }
    }
  }
  for (int i = 0; i < 5; i++) {
    if (scores[0][i] == -1 && scores[1][i] == -1) {
      diff[i] = 0;
    } else if (scores[0][i] == -1) {
      diff[i] = -1 * (250 - scores[1][i]);
    } else if (scores[1][i] == -1) {
      diff[i] = 250 - scores[0][i];
    } else {
      diff[i] = (250 - scores[0][i]) - (250 - scores[1][i]);
    }
  }
  int temp = n;
  while (n < 5000) {
    if (sum() > 0) {
      cout << n - temp << endl;
      return 0;
    }
    n++;
    for (int i = 0; i < 5; i++) {
      if (diff[i] < 0 && scores[0][i] > -1) {
        sn[i]++;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
