#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int a[5];
int b[5];
int cnt[5];
int n;
bool can(int m) {
  int A = 0, B = 0;
  for (int i = 0; i < (int)(5); ++i) {
    int j = 0, x = cnt[i] + (a[i] < b[i] && a[i]) * m;
    if (a[i] == 0 && b[i] == 0) {
      continue;
    }
    while (x <= n + m && j < 6) {
      ++j;
      x *= 2;
    }
    A += j * a[i];
    B += j * b[i];
  }
  return A > B;
}
int main() {
  cin >> n;
  for (int i = 0; i < (int)(5); ++i) {
    cin >> a[i];
    if (a[i] != -1) {
      a[i] = 250 - a[i];
      ++cnt[i];
    } else {
      a[i] = 0;
    }
  }
  for (int i = 0; i < (int)(5); ++i) {
    cin >> b[i];
    if (b[i] != -1) {
      b[i] = 250 - b[i];
      ++cnt[i];
    } else {
      b[i] = 0;
    }
  }
  for (int i = 0; i < (int)(n - 2); ++i) {
    for (int i = 0; i < (int)(5); ++i) {
      int x;
      cin >> x;
      if (x != -1) {
        ++cnt[i];
      }
    }
  }
  for (int i = 0; i < (int)(1000000); ++i) {
    if (can(i)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
