#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto const &vv : V) os << vv << ",";
  os << "]";
  return os;
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  os << "(" << P.first << "," << P.second << ")";
  return os;
}
template <typename T>
inline void print_128(T num) {
  if (!num) return;
  print_128(num / 10);
  cout.put((num % 10) + '0');
}
template <typename T>
inline T fstoi(const string &str) {
  auto it = str.begin();
  bool neg = 0;
  T num = 0;
  if (*it == '-')
    neg = 1;
  else
    num = *it - '0';
  ++it;
  while (it < str.end()) num = num * 10 + (*it++ - '0');
  if (neg) num *= -1;
  return num;
}
inline void getch(char &x) {
  while (x = getchar_unlocked(), x < 33) {
    ;
  }
}
inline void getstr(string &str) {
  str.clear();
  char cur;
  while (cur = getchar_unlocked(), cur < 33) {
    ;
  }
  while (cur > 32) {
    str += cur;
    cur = getchar_unlocked();
  }
}
template <typename... Args>
inline void getstr(string &str, Args &...arg) {
  str.clear();
  char cur;
  while (cur = getchar_unlocked(), cur < 33) {
    ;
  }
  while (cur > 32) {
    str += cur;
    cur = getchar_unlocked();
  }
  getstr(arg...);
}
template <typename T>
inline bool sc(T &num) {
  bool neg = 0;
  int c;
  num = 0;
  while (c = getchar_unlocked(), c < 33) {
    if (c == EOF) return false;
  }
  if (c == '-') {
    neg = 1;
    c = getchar_unlocked();
  }
  for (; c > 47; c = getchar_unlocked()) num = num * 10 + c - 48;
  if (neg) num *= -1;
  return true;
}
template <typename T, typename... Args>
inline void sc(T &num, Args &...args) {
  bool neg = 0;
  int c;
  num = 0;
  while (c = getchar_unlocked(), c < 33) {
    ;
  }
  if (c == '-') {
    neg = 1;
    c = getchar_unlocked();
  }
  for (; c > 47; c = getchar_unlocked()) num = num * 10 + c - 48;
  if (neg) num *= -1;
  sc(args...);
}
int n;
int arr[2][5];
int subm[5];
inline bool ok(int cur) {
  long long svas = 0, spet = 0;
  long double cont = n + cur;
  int val;
  long double per;
  for (int i = 0; i < 5; ++i) {
    if (arr[0][i] != -1 && (arr[0][i] > arr[1][i] && arr[1][i] != -1)) {
      per = (subm[i] + cur) / cont;
      if (per > 0.5)
        val = 500;
      else if (per > 0.25)
        val = 1000;
      else if (per > 0.125)
        val = 1500;
      else if (per > 0.0625)
        val = 2000;
      else if (per > 0.03125)
        val = 2500;
      else
        val = 3000;
      if (arr[0][i] != -1) {
        svas += val * (1 - arr[0][i] / 250.0);
      }
      if (arr[1][i] != -1) {
        spet += val * (1 - arr[1][i] / 250.0);
      }
    } else {
      per = subm[i] / cont;
      if (per > 0.5)
        val = 500;
      else if (per > 0.25)
        val = 1000;
      else if (per > 0.125)
        val = 1500;
      else if (per > 0.0625)
        val = 2000;
      else if (per > 0.03125)
        val = 2500;
      else
        val = 3000;
      if (arr[0][i] != -1) {
        svas += val * (1 - arr[0][i] / 250.0);
      }
      if (arr[1][i] != -1) {
        spet += val * (1 - arr[1][i] / 250.0);
      }
    }
  }
  return svas > spet ? 1 : 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  sc(n);
  for (int i = (0); i < int((2)); ++i) {
    sc(arr[i][0], arr[i][1], arr[i][2], arr[i][3], arr[i][4]);
    for (int e = (0); e < int((5)); ++e) {
      if (arr[i][e] != -1) ++subm[e];
    }
  }
  int t;
  for (int q = n - 2; q; --q) {
    for (int i = 0; i < 5; ++i) {
      sc(t);
      if (t != -1) ++subm[i];
    }
  }
  for (auto i = (0); i <= (1e7); ++i) {
    if (ok(i)) {
      cout << i << '\n';
      exit(0);
    };
  }
  cout << "-1\n";
}
