#include <bits/stdc++.h>
using namespace std;
double p[3][10];
int ac[10];
int point[6] = {500, 1000, 1500, 2000, 2500, 3000};
int N;
bool check(int ans) {
  int n = N + ans;
  double s1 = 0, s2 = 0;
  for (int i = 1; i <= 5; i++) {
    for (int j = 5; j >= 0; j--) {
      int need = (1 << j) * ac[i];
      if (need <= n) {
        s1 += p[1][i] * point[j];
        s2 += p[2][i] * point[j];
        break;
      }
    }
    if (p[1][i] < p[2][i] && p[1][i] != 0) ac[i]++;
  }
  if (s1 > s2)
    return true;
  else
    return false;
}
int main() {
  cin >> N;
  for (int i = 1; i <= 2; i++)
    for (int j = 1; j <= 5; j++) {
      int t;
      cin >> t;
      if (t != -1) {
        p[i][j] = 1 - t / 250.0;
        ac[j]++;
      } else
        p[i][j] = 0;
    }
  for (int i = 3; i <= N; i++)
    for (int j = 1; j <= 5; j++) {
      int t;
      cin >> t;
      if (t != -1) ac[j]++;
    }
  int ans;
  for (ans = 0; ans <= 120 * 35; ans++) {
    if (check(ans)) {
      cout << ans << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
