t = gets.to_i.times.map{gets.split.map(&:to_i).each_slice(2).map{|(h,m)|60*h+m}}
m = t.flatten.sort.uniq
r = 0
0.upto(m.size-3) do |i|
  (i+1).upto(m.size-2) do |j|
    (j+1).upto(m.size-1) do |k|
      s = 0
      t.each do |x|
        next unless (x[0]..x[1]).include? m[i]
        next unless (x[2]..x[3]).include? m[j]
        next unless (x[4]..x[5]).include? m[k]
        s += 1
      end
      r = [r, s].max
    end
  end
end
p r
exit

t = gets.to_i.times.map{gets.split.map(&:to_i).each_slice(2).map{|(h,m)|60*h+m}}
r = 0
t.each do |a|
  t.each do |b|
    t.each do |c|
      [0, 1].each do |i|
        [2, 3].each do |j|
          [4, 5].each do |k|
            s = 0
            t.each do |x|
              next unless (x[0]..x[1]).include? a[i]
              next unless (x[2]..x[3]).include? b[j]
              next unless (x[4]..x[5]).include? c[k]
              s += 1
            end
            r = [r, s].max
          end
        end
      end
    end
  end
end
p r