#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    vector<ll> s[N];
    for (int i = 0; i < N; i++) {
        int M;
        cin >> M;
        for (int j = 0; j < M; j++) {
            int c;
            cin >> c;
            s[i].push_back(c);
        }
    }
    
    ll sum = 0;
    priority_queue<ll, vector<ll>> pq;
    for (int i = N - 1; i >= 0; i--) {
        for (int j = 0; j < s[i].size(); j++) {
            pq.push(s[i][j]);
        }
        sum += pq.top();
        pq.pop();
    }
    
    cout << sum << "\n";
    return 0;
}
