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
	
	for city in range(last_city, M):
		if not bought_crane:
			for crane, price in cities[city].items():
				work(city+1, crane, price, profit-price)
			work(city+1, None, None, profit)
		if bought_crane:
			work(city+1, bought_crane, price, profit)
			if cities[city].get(bought_crane) and cities[city].get(bought_crane) > price:
				work(city, None, None, profit+cities[city].get(bought_crane))

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