import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int M = sc.nextInt();
for(int i = 0; i < N; ++i){
int r = 1;
List<Set<List<Integer>>> v = new ArrayList<>();
for(int j = 0; j < M; ++j){//输入部分开始
int n = sc.nextInt();
Set<List<Integer>> temp = new HashSet<>();
for(int k = 0; k < n; ++k){
int a = sc.nextInt();
int b = sc.nextInt();
List<Integer> c = new ArrayList<>();
c.add(a);
c.add(b);
temp.add(c);
}
v.add(temp);
}//输入部分结束
for(int j = 0; j < M - 1; ++j){//连续特征长度从当前这行开始数
Set<List<Integer>> temp = v.get(j);
Map<List<Integer>, Integer> bwt = new HashMap<>();
for(List<Integer> k : temp) bwt.put(k, 1);//每个特征都是从1开始数
for(int k = j + 1; k < M; ++k){
for(List<Integer> p : temp){
if(!v.get(k).contains(p)) {
int y = bwt.get(p);
if(y > r) r = y;//连续特征中断时,更新全局最优解
bwt.put(p, 0);//用0作为连续特征发生中断的标志
}
}
for(List<Integer> p : v.get(k)){
if(temp.contains(p)){
int y = bwt.get(p);
if(y != 0) bwt.put(p, y + 1);//已中断的特征不再计数
}
}
}
int z = 1;
for(Integer bwti : bwt.values()){//找到当前这行开始的最长特征链长度
if(bwti > z) z = bwti;
}
if(z > r) r = z;//更新全局最优解(那些一直到末尾都没中断的连续特征)
}
System.out.println(r);
}
}
}