
import java.util.*;
import java.util.stream.Collectors;
public class Main {
static List<Integer>[] database;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String lines = sc.nextLine();
String[] nandk = lines.split(" ");
int n = Integer.valueOf(nandk[0]);
int k = Integer.valueOf(nandk[1]);
database = new ArrayList[k + 1];
for (int i = 0; i < database.length; i++) {
database[i] = new ArrayList<>();
}
while (n > 0) {
String line = sc.nextLine();
if (line.startsWith("1")) {
insert(line);
} else if (line.startsWith("2")) {
search(line);
}
n--;
}
}
public static void insert(String line) {
String[] s = line.split(" ");
int n = Integer.valueOf(s[1]);
int i = 2;
while (n > 0) {
database[Integer.valueOf(s[i++])].add(Integer.valueOf(s[i++]));
n--;
}
}
public static void search(String line) {
String[] s = line.split(" ");
int target = Integer.valueOf(s[1]);
int left = Integer.valueOf(s[2]);
int right = Integer.valueOf(s[3]);
if (left >= database.length){
System.out.println("0");
return;
}
int res = 0;
for (int i = left; i <= right; i++) {
res += database[i].stream().filter(item -> !item.equals(target)).count();
}
System.out.println(res);
}
}