#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1000000000;
const long long int mod = 1000000000 + 7;
inline void IO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
inline int dcmp(long double x) { return x < -1e-12 ? -1 : (x > 1e-12); }
template <class T>
inline int CHECK(T MASK, int i) {
  return (MASK >> i) & 1;
}
template <class T>
inline T ON(T MASK, int i) {
  return MASK | (T(1) << i);
}
template <class T>
inline T OFF(T MASK, int i) {
  return MASK & (~(T(1) << i));
}
template <typename T>
inline int CNT(T MASK) {
  if (numeric_limits<T>::digits <= numeric_limits<unsigned int>::digits)
    return __builtin_popcount(MASK);
  else
    return __builtin_popcountll(MASK);
}
template <class T>
inline int RIGHT(T MASK) {
  return log2(MASK & -MASK);
}
int dx4[] = {0, 0, -1, +1};
int dy4[] = {+1, -1, 0, 0};
int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
inline void I(int& a) { scanf("%d", &a); }
inline void I(long long int& a) { scanf("%I64d", &a); }
inline void I(unsigned long long int& a) { scanf("%I64u", &a); }
inline void I(char* a) { scanf("%s", a); }
char Iarr[2000010];
inline void I(string& a) {
  scanf("%s", Iarr);
  a = Iarr;
}
template <typename T, typename... Args>
void I(T& a, Args&... args) {
  I(a);
  I(args...);
}
inline void OUT(int a) { printf("%d", a); }
inline void OUT(long long int a) { printf("%I64d", a); }
inline void OUT(const char* a) { printf("%s", a); }
inline void OUT(char* a) { printf("%s", a); }
inline void OUT(bool a) { printf("%d", a); }
inline void OUT(string a) {
  for (__typeof(a.end()) it = (a.begin()) - ((a.begin()) > (a.end()));
       it != (a.end()) - ((a.begin()) > (a.end()));
       it += 1 - 2 * ((a.begin()) > (a.end())))
    printf("%c", *it);
}
inline void OUT(unsigned long long int a) { printf("%I64u", a); }
template <typename T, typename... Args>
void OUT(T a, Args... args) {
  OUT(a);
  OUT(" ");
  OUT(args...);
}
template <typename... Args>
void O(Args... args) {
  OUT(args...);
  OUT("\n");
}
template <typename T1, typename T2>
inline ostream& operator<<(ostream& os, pair<T1, T2> p) {
  os << "{" << p.first << ", " << p.second << "}";
  return os;
}
template <typename T>
inline ostream& operator<<(ostream& os, vector<T>& a) {
  os << "[";
  for (int i = 0; i < (int)a.size(); i++) {
    if (i) os << ", ";
    os << a[i];
  }
  os << "]";
  return os;
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cout << *it << " = " << a << endl;
  err(++it, args...);
}
const int M = 130;
long long int participants;
long long int solved[5];
long long int a[M][5];
bool le(long double r, long double cmp) {
  long double d = r - cmp;
  if (dcmp(d) == -1)
    return 1;
  else if (dcmp(d) == 0)
    return 1;
  return 0;
}
long long int calc(long double r) {
  if (le(r, 1.0 / 32))
    return 3000;
  else if (le(r, 1.0 / 16))
    return 2500;
  else if (le(r, 1.0 / 8))
    return 2000;
  else if (le(r, 1.0 / 4))
    return 1500;
  else if (le(r, 1.0 / 2))
    return 1000;
  else
    return 500;
}
bool ok(long long int n) {
  long long int temp = participants + n;
  long long int solvedT[5];
  bool flag = 0;
  for (int i = 0; i < 5; i++) {
    solvedT[i] = solved[i];
    if ((a[0][i] > a[1][i] && a[1][i] != -1)) {
      solvedT[i] += n;
      flag = 1;
    }
  }
  long long int vasya = 0;
  long long int petya = 0;
  for (int i = 0; i < 5; i++) {
  }
  for (int i = 0; i < 5; i++) {
    long double R = (long double)solvedT[i] / (long double)temp;
    long long int x = calc(R);
    if (a[0][i] != -1) {
      vasya += x - (x / 250) * a[0][i];
    }
    if (a[1][i] != -1) {
      petya += x - (x / 250) * a[1][i];
    }
  }
  if (vasya > petya)
    return 1;
  else
    return 0;
}
long long int func() {
  long long int low = 0, high = mod;
  while (low < high) {
    long long int mid = (low + high) / 2;
    if (ok(mid))
      high = mid;
    else
      low = mid + 1;
  }
  if (ok(low)) return low;
  return -1;
}
int main() {
  int n;
  I(n);
  participants = n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5; j++) {
      I(a[i][j]);
      if (a[i][j] != -1) {
        solved[j]++;
      }
    }
  }
  for (int i = 0; i <= M * 32; i++) {
    if (ok(i)) {
      O(i);
      exit(0);
    }
  }
  O(-1);
  return 0;
}
