#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
	int n; cin >> n;
	vector<int> v[300000];
	for (int i = 0; i < n; i++) {
		int m, c; cin >> m;
		while (m--) {
			cin >> c;
			v[i].push_back(c);
		}
	}
	priority_queue<int> pq;
	long long ans = 0;
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < v[i].size(); ++j) pq.push(v[i][j]);
		ans += pq.top(); pq.pop();
	}
	cout << ans << endl;

	return 0;
}
