require 'time' ret = Array.new(gets.to_i) do start, finish = gets.split.map do |str| Time.parse(str) end finish += 86400 if start > finish ((finish - start) / 60).to_i end puts ret.inject(&:+)