#include <bits/stdc++.h>
using namespace std;
long long int n;
long long int arr[1000][5];
bool tohack[6];
long long int alreadysolved[6] = {0};
long long int bitmask;
inline void tosolve() {
  for (long long int i = 0; i < 6; i += 1) {
    if (bitmask & (1 << i)) {
      if (arr[0][i] != -1) {
        tohack[i] = true;
      }
    }
  }
}
inline long long int pointsoftheproblem(long long int fakeid,
                                        long long int problemno) {
  long long int totsolved = fakeid + alreadysolved[problemno];
  if (tohack[problemno] == false || bitmask == 0) {
    totsolved -= fakeid;
  }
  long long int totpart = fakeid + n;
  if (bitmask == 0) {
    totpart -= fakeid;
  }
  if ((double)totsolved / totpart > (double)1.0 / 2) {
    return 500;
  } else if ((double)totsolved / totpart > (double)1.0 / 4) {
    return 1000;
  } else if ((double)totsolved / totpart > (double)1.0 / 8) {
    return 1500;
  } else if ((double)totsolved / totpart > (double)1.0 / 16) {
    return 2000;
  } else if ((double)totsolved / totpart > (double)1.0 / 32) {
    return 2500;
  } else {
    return 3000;
  }
}
bool check(long long int mid) {
  long long int pntsofVaysa = 0;
  for (int i = 0; i < 5; i += 1) {
    if (arr[0][i] != -1) {
      pntsofVaysa += (pointsoftheproblem(mid, i) * (250 - arr[0][i])) / 250;
    }
  }
  long long int pntsofsecond = 0;
  for (int i = 0; i < 5; i += 1) {
    if (arr[1][i] != -1) {
      pntsofsecond += (pointsoftheproblem(mid, i) * (250 - arr[1][i])) / 250;
    }
  }
  return pntsofVaysa > pntsofsecond;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i += 1) {
    for (int j = 0; j < 5; j += 1) {
      cin >> arr[i][j];
      if (arr[i][j] != -1) {
        alreadysolved[j] += 1;
      }
    }
  }
  long long int ans = (long long int)1e18;
  for (int j = 0; j <= (1 << 5) - 1; j += 1) {
    for (int i = 0; i < 6; i += 1) {
      tohack[i] = false;
    }
    bitmask = j;
    tosolve();
    for (long long int j = 0; j <= (long long int)1e5; j += 1) {
      if (check(j)) {
        ans = min(ans, j);
      }
    }
  }
  if (ans > 1e9 + 7) {
    cout << "-1" << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
