Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.

For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.

<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/da99bea423afb93b32a3ba5c356290b9ddb669f5.png" style="max-width: 100.0%;max-height: 100.0%;"/>

Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.

If the problem's maximum point value is equal to *x*, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses *x* / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.

There are *n* participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.

With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.

Unfortunately, Vasya is a cheater. He has registered 10<sup class="upper-index">9</sup> + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.

Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.

Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
The first line contains a single integer *n* (2 ≤ *n* ≤ 120) — the number of round participants, including Vasya and Petya.

Each of the next *n* lines contains five integers *a*<sub class="lower-index">*i*, 1</sub>, *a*<sub class="lower-index">*i*, 2</sub>..., *a*<sub class="lower-index">*i*, 5</sub> ( - 1 ≤ *a*<sub class="lower-index">*i*, *j*</sub> ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem *j* by participant *i*, or -1 if participant *i* hasn't solved problem *j*.

It is guaranteed that each participant has made at least one successful submission.

Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.

In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.

In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
2
5 15 40 70 115
50 45 40 30 15
2
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
3
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
27
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
-1
2
33 15 51 7 101
41 80 40 13 46
0
9
57 52 60 56 91
32 40 107 89 36
80 0 45 92 119
62 9 107 24 61
43 28 4 26 113
31 91 86 13 95
4 2 88 38 68
83 35 57 101 28
12 40 37 56 73
9
19
78 100 74 31 2
27 45 72 63 0
42 114 31 106 79
88 119 118 69 90
68 14 90 104 70
106 21 96 15 73
75 66 54 46 107
108 49 17 34 90
76 112 49 56 76
34 43 5 57 67
47 43 114 73 109
79 118 69 22 19
31 74 21 84 79
1 64 88 97 79
115 14 119 101 28
55 9 43 67 10
33 40 26 10 11
92 0 60 14 48
58 57 8 12 118
133
17
66 15 -1 42 90
67 108 104 16 110
76 -1 -1 -1 96
108 32 100 91 17
87 -1 85 10 -1
70 55 102 15 23
-1 33 111 105 63
-1 56 104 68 116
56 111 102 89 63
63 -1 68 80 -1
80 61 -1 81 19
101 -1 87 -1 89
92 82 4 105 83
19 30 114 77 104
100 99 29 68 82
98 -1 62 52 -1
108 -1 -1 50 -1
5
3
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
3
4
66 55 95 78 114
70 98 8 95 95
17 47 88 71 18
23 22 9 104 38
4
10
-1 18 44 61 115
-1 34 12 40 114
-1 86 100 119 58
-1 4 36 8 91
1 58 85 13 82
-1 9 85 109 -1
13 75 0 71 42
116 75 42 79 88
62 -1 98 114 -1
68 96 44 61 35
62
26
3 -1 71 -1 42
85 72 48 38 -1
-1 -1 66 24 -1
46 -1 60 99 107
53 106 51 -1 104
-1 17 98 54 -1
44 107 66 65 102
47 40 62 34 5
-1 10 -1 98 -1
-1 69 47 85 75
12 62 -1 15 -1
48 63 72 32 99
91 104 111 -1 -1
92 -1 52 -1 11
118 25 97 1 108
-1 61 97 37 -1
87 47 -1 -1 21
79 87 73 82 70
90 108 19 25 57
37 -1 51 8 119
64 -1 -1 38 82
42 61 63 25 27
82 -1 15 82 15
-1 89 73 95 -1
4 8 -1 70 116
89 21 65 -1 88
10
2
0 0 0 0 1
0 0 0 1 0
2
#!/usr/bin/python3
# Copyright (C) 2017 Sayutin Dmitry.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; version 3
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; If not, see <http://www.gnu.org/licenses/>.

def get_price(a, b):
    # a / b
    if 2 * a > b:
        return 500
    if 4 * a > b:
        return 1000
    if 8 * a > b:
        return 1500
    if 16 * a > b:
        return 2000
    if 32 * a > b:
        return 2500
    return 3000

def main():
    n = int(input())
    we = list(map(int, input().split()))
    fr = list(map(int, input().split()))

    ratio = [0, 0, 0, 0, 0]
    for i in range(5):
        if we[i] != -1:
            ratio[i] += 1
        else:
            we[i] = 250
        
        if fr[i] != -1:
            ratio[i] += 1
        else:
            fr[i] = 250

    for part in range(n - 2):
        lst = list(map(int, input().split()))
        for i in range(5):
            if lst[i] != -1:
                ratio[i] += 1

                
    for mi in range(0, 4500):
        s1 = 0
        s2 = 0

        for i in range(5):
            if we[i] < fr[i]:
               pr = get_price(ratio[i] + 0, n + mi)
               
               s1 += pr - pr * we[i] // 250
               s2 += pr - pr * fr[i] // 250
            elif we[i] > fr[i] and we[i] != 250: # submit as much OK as we can
                pr = get_price(ratio[i] + mi, n + mi)

                s1 += pr - pr * we[i] // 250
                s2 += pr - pr * fr[i] // 250
            elif we[i] > fr[i] and we[i] == 250:
                pr = get_price(ratio[i] + mi, n + mi)

                s1 += pr - pr * we[i] // 250
                s2 += pr - pr * fr[i] // 250
                
        if s1 > s2:
            print(mi)
            return

    lo = 4450
    hi = 10 ** 9 + 8 # OK

    while hi - lo > 1:
        mi = lo + (hi - lo) // 2
        
        s1 = 0
        s2 = 0

        for i in range(5):
            if we[i] < fr[i]:
               pr = get_price(ratio[i] + 0, n + mi)
               
               s1 += pr - pr * we[i] // 250
               s2 += pr - pr * fr[i] // 250
            elif we[i] > fr[i] and we[i] != 250: # submit as much OK as we can
                pr = get_price(ratio[i] + mi, n + mi)

                s1 += pr - pr * we[i] // 250
                s2 += pr - pr * fr[i] // 250
            elif we[i] > fr[i] and we[i] == 250:
                pr = get_price(ratio[i] + mi, n + mi)

                s1 += pr - pr * we[i] // 250
                s2 += pr - pr * fr[i] // 250
                
        if s1 > s2:
            hi = mi
        else:
            lo = mi
    
    print(-1 if hi == 10 ** 9 + 8 else hi)
main()
