import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int[] res = new int[n];
int count = 0;
ArrayList<data> data = new ArrayList<>();
for (int i = 0;i < n;i++){
int type = sc.nextInt();
if(type == 1){
int num = sc.nextInt();
for(int j = 0;j < num;j++){
int id = sc.nextInt();
int value = sc.nextInt();
data dt = new data(id,value);
data.add(dt);
}
} else if (type == 2) {
int ser = sc.nextInt();
int start = sc.nextInt();
int end = sc.nextInt();
for (int j = (start-1);j <= (end-1) && j < data.size();j++){
if(ser == data.get(j).value){
res[count]+=1;
}
}
count++;
}
}
for (int i = 0; i < count;i++){
System.out.println(res[i]);
}
}
}
class data{
int id;
int value;
public data(int id, int value) {
this.id = id;
this.value = value;
}
}