M = int(input())

cities = {}


for city in range(M):
	number_of_cranes = int(input())
	cities[city] = {}
	for crane in range(number_of_cranes):
		crane_id, crane_price = (int(i)for i in input().split())
		cities[city][crane_id] = crane_price

max_profit = 0
def work(last_city, bought_crane, price, profit):
	global max_profit
	if profit > max_profit:
		max_profit = profit
	if last_city >= M:
		return
	if not bought_crane:
		for crane, price in cities[last_city].items():
			work(last_city+1, crane, price, profit-price)
		work(last_city+1, None, None, profit)
	if bought_crane:
		work(last_city+1, bought_crane, price, profit)
		if cities[last_city].get(bought_crane) and cities[last_city].get(bought_crane) > price:
			work(last_city, None, None, profit+cities[last_city].get(bought_crane))

work(0, None, None, 0)
print(max_profit)
