#include <iostream>
#include <utility>
#include <vector>
using namespace std;
const int MAX = 307;
struct Interval
{
int left, right;
};
int n;
vector<vector<Interval>> Intervals;
int Delimiters[MAX];
int main()
{
cin >> n;
Intervals.resize(n);
for (int i = 0; i < n; ++i)
{
int s, c;
cin >> s >> c;
for (int j = 0; j < c; ++j)
{
int t;
cin >> t;
int l = min(s, t);
int r = max(s, t);
Intervals[i].push_back(Interval{l + 1, r});
}
}
int res = 0;
for (int left = 0; left < MAX; ++left)
{
for (int right = left + 1; right < MAX; ++right)
{
bool containsAtLeastOneCompany = false;
for (auto &IntervalsPerCompany : Intervals)
{
for (auto &Interval : IntervalsPerCompany)
{
if (Interval.left > left && Interval.right < right)
{
containsAtLeastOneCompany = true;
}
}
}
bool allCompaniesFit = true;
for (auto &IntervalsPerCompany : Intervals)
{
bool companyFits = false;
for (auto &Interval : IntervalsPerCompany)
{
bool collisionLeft = Interval.left <= left && Interval.right >= left;
bool collisionRight = Interval.left <= right && Interval.right >= right;
if (!collisionLeft && !collisionRight)
{
companyFits = true;
}
}
if (!companyFits)
{
allCompaniesFit = false;
}
}
if (allCompaniesFit && containsAtLeastOneCompany)
{
Delimiters[right] = max(Delimiters[right], Delimiters[left] + 1);
}
}
res = max(res, Delimiters[left]);
}
cout << res << endl;
return 0;
}