#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<tuple>
#include<queue>
#include<set>
#include<unordered_map>
#include<string>
#include<map>
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> P;
typedef pair<int, P> PP;
const long long inf = 1ll << 61;
const int mod = 1000000007;
vector<int>c[300005];
signed main() {
	int n; cin >> n;
	rep(i, n) {
		int m; cin >> m;
		rep(j, m) {
			int x; cin >> x; c[i].push_back(x);
		}
	}
	priority_queue<int>Q;
	int ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		rep(j, c[i].size())Q.push(c[i][j]);
		ans += Q.top();
		Q.pop();
	}
	cout << ans << endl;
}

