#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007LL;
long long base = 37;
long long large = 1000000000000000000LL;
int f(int a, int b) {
  int ans = 500;
  if (2 * a <= b) ans += 500;
  if (4 * a <= b) ans += 500;
  if (8 * a <= b) ans += 500;
  if (16 * a <= b) ans += 500;
  if (32 * a <= b) ans += 500;
  return ans;
}
int g(int s, int t) { return s - s / 250 * t; }
int main() {
  int n;
  cin >> n;
  vector<int> a(5, 0);
  vector<int> b = a;
  for (int i = 0; i < 5; i++) cin >> a[i];
  for (int i = 0; i < 5; i++) cin >> b[i];
  vector<int> cnt(5, 0);
  for (int i = 0; i < n - 2; i++) {
    for (int j = 0; j < 5; j++) {
      int x;
      cin >> x;
      if (x != -1) cnt[j]++;
    }
  }
  int ans = -1;
  for (int c = 0; c < 30000; c++) {
    int s1 = 0;
    int s2 = 0;
    for (int j = 0; j < 5; j++) {
      if (a[j] != -1 && b[j] == -1) {
        s1 += g(f(cnt[j] + 1, n + c), a[j]);
      }
      if (a[j] == -1 && b[j] != -1) {
        s2 += g(f(cnt[j] + 1, n + c), b[j]);
      }
      if (a[j] != -1 && b[j] != -1) {
        if (a[j] <= b[j]) {
          s1 += g(f(cnt[j] + 2, n + c), a[j]);
          s2 += g(f(cnt[j] + 2, n + c), b[j]);
        } else {
          s1 += g(f(cnt[j] + 2 + c, n + c), a[j]);
          s2 += g(f(cnt[j] + 2 + c, n + c), b[j]);
        }
      }
    }
    if (s1 > s2) {
      ans = c;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
