arr = []
line = gets.chomp.split
line[1..-1].each{|str| arr << [str[0, 2].to_i * 60 + str[3, 2].to_i, str[6, 2].to_i * 60 + str[9, 2].to_i]}
arr2 = Array.new(arr.length){[0, 0]}

gets.to_i.times{
    ar = []
    line = gets.chomp.split
    line[1..-1].each{|str| ar << [str[0, 2].to_i * 60 + str[3, 2].to_i, str[6, 2].to_i * 60 + str[9, 2].to_i]}
    arr.each_with_index{|item, i| ar.each{|st, et| arr2[i][0] += 1 if item[0] >= st && item[1] <= et}}
}

gets.to_i.times{
    ar = []
    line = gets.chomp.split
    line[1..-1].each{|str| ar << [str[0, 2].to_i * 60 + str[3, 2].to_i, str[6, 2].to_i * 60 + str[9, 2].to_i]}
    arr.each_with_index{|item, i| ar.each{|st, et| arr2[i][1] += 1 if item[0] >= st && item[1] <= et}}
}

sum = 0
arr2.each{|ar| sum += ar.min}
puts sum

