n = gets.to_i
arr = Array.new(1440){[]}, Array.new(1440){[]}, Array.new(1440){[]}
n.times{|member|
	line = gets.chomp.split.map(&:to_i)
	3.times{|i| (line[i * 4] * 60 + line[i * 4 + 1]).upto(line[i * 4 + 2] * 60 + line[i * 4 + 3]){|j| arr[i][j] << member}}
}
3.times{|i|
	arr[i].uniq!
	arr[i].delete []
}
max = 0
arr[0].each{|ar0|
	arr[1].each{|ar1|
		arr[2].each{|ar2|
			l = (ar0 & ar1 & ar2).length
			max = l if max < l
		}
	}
}
puts max
