month = [31 28 31 30 31 30 31 31 30 31 30 31]
day = [0 for i in range(366)]
check = []
count = 0
list = [[] [] [] []]
def changetoday(M):
global month
sum = 0
for i in range(M-1):
sum += month[i]
return sum
n = int(input())
for i in range(n):
sm sd em ed = map(int input().split())
list[0].append(sm)
list[1].append(sd)
list[2].append(em)
list[3].append(ed)
def ret(c) :
global n
global count
global check
if c > 334:
return count
count += 1
for i in range(n):
if changetoday(list[0][i])+list[1][i] < c:
check.append(i)
if len(check) == 0:
return 0
else:
m = 0
for i in range(len(check)):
s = changetoday(list[2][check[i]]) + list[3][check[i]]
if s > m:
m = s
k = i #
print(list[0][check[k]]"/"list[1][check[k]]" ~ "list[2][check[k]]"/"list[3][check[k]]) #
return ret(m)
# \('^')/
# |||
# ` `
print(ret(60))