#include <bits/stdc++.h>
using namespace std;
long long int d[1000005];
int k[200][5];
int solve[5];
int n;
bool check(long long int d) {
  int i, j;
  long long int sb = 0;
  long long int sa = 0;
  long long int u = n + d;
  for (i = 0; i < 5; i++) {
    if (k[0][i] == -1 && k[1][i] == -1) {
    } else if (k[0][i] == -1) {
      if (n + d >= (solve[i] + 1) * 32) {
        sb += (250 - k[1][i]) * 12;
      } else if (n + d >= (solve[i] + 1) * 16) {
        sb += (250 - k[1][i]) * 10;
      } else if (n + d >= (solve[i] + 1) * 8) {
        sb += (250 - k[1][i]) * 8;
      } else if (n + d >= (solve[i] + 1) * 4) {
        sb += (250 - k[1][i]) * 6;
      } else if (n + d >= (solve[i] + 1) * 2) {
        sb += (250 - k[1][i]) * 4;
      } else {
        sb += (250 - k[1][i]) * 2;
      }
    } else if (k[1][i] == -1) {
      if (n + d >= (solve[i] + 1) * 32) {
        sa += (250 - k[0][i]) * 12;
      } else if (n + d >= (solve[i] + 1) * 16) {
        sa += (250 - k[0][i]) * 10;
      } else if (n + d >= (solve[i] + 1) * 8) {
        sa += (250 - k[0][i]) * 8;
      } else if (n + d >= (solve[i] + 1) * 4) {
        sa += (250 - k[0][i]) * 6;
      } else if (n + d >= (solve[i] + 1) * 2) {
        sa += (250 - k[0][i]) * 4;
      } else {
        sa += (250 - k[0][i]) * 2;
      }
    } else if (k[1][i] < k[0][i]) {
      if (n + d >= (solve[i] + 2 + d) * 32) {
        sa += (250 - k[0][i]) * 12;
        sb += (250 - k[1][i]) * 12;
      } else if (n + d >= (solve[i] + 2 + d) * 16) {
        sa += (250 - k[0][i]) * 10;
        sb += (250 - k[1][i]) * 10;
      } else if (n + d >= (solve[i] + 2 + d) * 8) {
        sa += (250 - k[0][i]) * 8;
        sb += (250 - k[1][i]) * 8;
      } else if (n + d >= (solve[i] + 2 + d) * 4) {
        sa += (250 - k[0][i]) * 6;
        sb += (250 - k[1][i]) * 6;
      } else if (n + d >= (solve[i] + 2 + d) * 2) {
        sa += (250 - k[0][i]) * 4;
        sb += (250 - k[1][i]) * 4;
      } else {
        sa += (250 - k[0][i]) * 2;
        sb += (250 - k[1][i]) * 2;
      }
    } else {
      if (n + d >= (solve[i] + 2) * 32) {
        sa += (250 - k[0][i]) * 12;
        sb += (250 - k[1][i]) * 12;
      } else if (n + d >= (solve[i] + 2) * 16) {
        sa += (250 - k[0][i]) * 10;
        sb += (250 - k[1][i]) * 10;
      } else if (n + d >= (solve[i] + 2) * 8) {
        sa += (250 - k[0][i]) * 8;
        sb += (250 - k[1][i]) * 8;
      } else if (n + d >= (solve[i] + 2) * 4) {
        sa += (250 - k[0][i]) * 6;
        sb += (250 - k[1][i]) * 6;
      } else if (n + d >= (solve[i] + 2) * 2) {
        sa += (250 - k[0][i]) * 4;
        sb += (250 - k[1][i]) * 4;
      } else {
        sa += (250 - k[0][i]) * 2;
        sb += (250 - k[1][i]) * 2;
      }
    }
  }
  if (sa > sb)
    return true;
  else
    return false;
}
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  long long int ans;
  cin >> n;
  int i, j;
  for (i = 0; i < n; i++) {
    for (j = 0; j < 5; j++) {
      cin >> k[i][j];
    }
  }
  for (i = 2; i < n; i++) {
    for (j = 0; j < 5; j++) {
      if (k[i][j] != -1) solve[j]++;
    }
  }
  long long int low, high, mid;
  low = 0;
  high = 1000000007;
  for (i = 0; i <= 1000000; i++) {
    if (check(i)) break;
  }
  if (i > 1000000)
    cout << -1;
  else
    cout << i << endl;
}
