#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long LL;
typedef bitset<5005> BIT;
const int MAXN = 5005;
bitset<55> a[MAXN];
BIT b[55];
int ans,n;

int main()
{
	//freopen("1.in","r",stdin);
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		int tot;
		scanf("%d",&tot);
		for (int j=0;j<tot;j++)
		{
			int x;
			scanf("%d",&x);
			a[i][x-1] = 1;
			//b[x-1][i] = 1;
		}
	}
	int ret = 0;
	BIT tmp,ans;
	for (int i=1;i<=n;i++)
	{
		ans.reset();
		tmp.reset();
		//Max = 0;
		for (int j=0;j<50;j++)
		{
			tmp = tmp | (b[j]);
			if (a[i][j]==1)
			{
				ans = ans ^ tmp;
				tmp.reset();
				b[j][i] = 1;
			}
		}
		//cout<<i<<' '<<ans.count()<<endl;
		ret+=ans.count();
		if (ans[i]==1) ret--;
	}
	printf("%d\n",ret);
}
