#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmin(T& x, const T& y) {
  if (y < x) {
    x = y;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T& x, const T& y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}
template <class T, class P>
ostream& operator<<(ostream& os, const pair<T, P>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "[";
  bool was = false;
  for (const T& x : v) {
    if (was) {
      os << ", ";
    } else {
      was = true;
    }
    os << x;
  }
  os << "]";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& v) {
  os << "[";
  bool was = false;
  for (const T& x : v) {
    if (was) {
      os << ", ";
    } else {
      was = true;
    }
    os << x;
  }
  os << "]";
  return os;
}
template <class T, class P>
ostream& operator<<(ostream& os, const map<T, P>& v) {
  os << "[";
  bool was = false;
  for (const auto& x : v) {
    if (was) {
      os << ", ";
    } else {
      was = true;
    }
    os << x;
  }
  os << "]";
  return os;
}
template <class T>
T sqr(const T& x) {
  return x * x;
}
const int maxn = 123;
int a[maxn][5];
int cnt[5];
int dp[maxn][6], tp[maxn][6];
int gettype(int x, int y) {
  for (int i = 0; i < 5; i++) {
    y *= 2;
    if (y > x) {
      return i;
    }
  }
  return 5;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 5; j++) {
      cin >> a[i][j];
      if (a[i][j] != -1) {
        cnt[j]++;
      }
    }
  }
  int ans = -1;
  for (int k = 0; k < 1e6; k++) {
    vector<int> pt(2);
    for (int j = 0; j < 5; j++) {
      int tp = gettype(n + k, cnt[j]);
      for (int i = 1; i <= 2; i++) {
        if (a[i][j] != -1) {
          pt[i - 1] += 500 * (tp + 1) - 2 * (tp + 1) * a[i][j];
        }
      }
    }
    if (pt[0] > pt[1]) {
      ans = k;
      break;
    }
    for (int j = 0; j < 5; j++) {
      if (a[1][j] != -1) {
        if (a[2][j] != -1 && a[2][j] < a[1][j]) {
          cnt[j]++;
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
