#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN = (int)1e5 + 42;
const int MAXM = (int)10;
int n, k;
int m[MAXN];
int64_t a[MAXN][MAXM];
void read()
{
cin >> n >> k;
for(int i = 0; i < n; i++)
{
cin >> m[i];
for(int j = 0; j < m[i]; j++)
cin >> a[i][j];
}
}
int64_t sum;
bool check(int64_t val)
{
if(val < sum) return false;
val -= sum;
int64_t ret = 1;
if(ret == k) return true;
map<int64_t, int64_t> cnt;
cnt[val] = 1;
for(int i = 0; i < n; i++)
{
vector<pair<int64_t, int64_t>> to_add;
for(int j = 1; j < m[i]; j++)
{
for(auto iter = prev(cnt.end()); ; --iter)
{
auto it = *iter;
if(it.first >= a[i][j])
{
ret += it.second;
if(ret >= k) return true;
to_add.push_back({it.first - a[i][j], it.second});
}
else break;
if(iter == cnt.begin()) break;
}
}
for(auto it: to_add)
cnt[it.first] += it.second;
}
return (ret >= k);
}
void solve()
{
sum = 0;
for(int i = n - 1; i >= 0; i--)
sort(a[i], a[i] + m[i]), sum += a[i][0];
for(int i = 0; i < n; i++)
for(int j = 1; j < m[i]; j++)
a[i][j] -= a[i][0];
int64_t low = 0, high = (int64_t)1e17 + 42, mid, ret;
while(low <= high)
{
mid = (low + high) >> 1ll;
if(check(mid)) high = mid - 1, ret = mid;
else low = mid + 1;
}
int64_t cnt = 1, ans = sum;
ret--;
ret -= sum;
map<int64_t, pair<int64_t, int64_t> > st;
st[ret] = {1, sum};
if(k == cnt)
{
cout << ans << endl;
return;
}
for(int i = 0; i < n; i++)
{
vector<pair<int64_t, pair<int64_t, int64_t>>> to_add;
for(int j = 1; j < m[i]; j++)
{
for(auto iter = prev(st.end()); ; --iter)
{
auto it = *iter;
if(it.first >= a[i][j])
{
int64_t delta = it.second.first;
cnt += delta;
ans += (it.second.second + a[i][j]) * delta;
to_add.push_back({it.first - a[i][j], {delta, delta * (it.second.second + a[i][j])}});
}
else break;
if(iter == st.begin()) break;
}
}
for(auto it: to_add)
{
st[it.first].first += it.second.first;
st[it.first].second += it.second.second;
}
}
while(cnt < k) cnt++, ans += ret + 1 + sum;
cout << ans << endl;
}
int main()
{
freopen("roboherd.in", "r", stdin);
freopen("roboherd.out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
read();
solve();
return 0;
}