Under construction

Still being built. Things may change

A Tree-Filled Tree Problem

Time limit2sMemory limit1024 MB

Summary
Given N lecture time intervals, find for each query the maximum number of non-overlapping lectures that includes the query's mandatory lectures.
Level

Medium6 of 10

Topics
Intervals, Greedy, Binary search
Solved
No attempts yet

Problem

Jiho had to write a tree problem, but he had already written one that uses trees in its solution. So this time he decided to write a problem whose statement is full of trees.

To write a good problem whose statement is full of trees, he needs to take many tree lectures and learn a lot of tree-related knowledge. Luckily, Gyeonggi Science High School, which loves trees, has NN good tree lectures. The ii-th tree lecture runs from time aia_i to bib_i, and attending it gives 11 unit of tree knowledge. If two tree lectures do not overlap in time, Jiho can attend both and study more about trees to write a better tree problem. Also, if ai=bja_i = b_j or bi=ajb_i = a_j for two lectures, they count as overlapping.

Some of the NN tree lectures are mandatory, and Jiho can freely sign up for the rest as long as they do not overlap in time. Find the maximum amount of tree knowledge Jiho can obtain.

Jiho does not yet know which tree lectures are mandatory. For each of the MM queries, a few mandatory tree lectures are given. For each query, print the maximum amount of tree knowledge Jiho can obtain.

Input

The first line contains NN and MM, separated by a space.

From the second line onward, the ii-th of the next NN lines contains two integers aia_i and bib_i, separated by a space, which are the start and end times of the ii-th tree lecture.

The following MM lines each contain one query. Each query gives the number ss of mandatory tree lectures, followed by the ss lecture numbers p1,p2,⋯ ,psp_1, p_2, \cdots, p_s, all separated by spaces.

Output

Print MM lines. The ii-th line contains the maximum amount of tree knowledge Jiho can obtain for the ii-th query.

Constraints

  • 1≤N,M≤300 0001 \leq N, M \leq 300\,000
  • 1≤ai<bi≤1091 \leq a_i < b_i \leq 10^9 (1≤i≤N1 \leq i \leq N)
  • (The sum of ss over all queries) ≤300 000\leq 300\,000
  • In each query, bpi<api+1b_{p_i} < a_{p_{i+1}} (1≤i<s1 \leq i < s)
  • In each query, s>0s>0

Hint

Two different tree lectures may start and end at exactly the same time.

The word "tree" appears 36 times in this statement (38 times including the title).

Examples1

  1. Example 1

    Input
    10 5
    1 3
    2 4
    3 5
    4 6
    5 7
    5 7
    6 8
    6 9
    8 10
    4 11
    1 1
    1 6
    1 10
    2 1 10
    3 1 4 9
    
    Expected output
    3
    3
    2
    2
    3