Problem: Valera loves segments. He has recently come up with one interesting problem.

The Ox axis of coordinates has n segments, the i-th segment starts in position li and ends in position ri (we will mark it as [li, ri]). Your task is to process m queries, each consists of number cnti and a set of cnti coordinates of points located on the Ox axis. The answer to the query is the number of segments, such that each of them contains at least one point from the query. Segment [l, r] contains point q, if l ≤ q ≤ r.

Valera found the solution of this problem too difficult. So he asked you to help him. Help Valera. 

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 3·105) — the number of segments on the axis of coordinates and the number of queries. 

Next n lines contain the descriptions of the segments. The i-th line contains two positive integers li, ri (1 ≤ li ≤ ri ≤ 106) — the borders of the i-th segment.

Next m lines contain the description of the queries, one per line. Each line starts from integer cnti (1 ≤ cnti ≤ 3·105) — the number of points in the i-th query. Then the line contains cnti distinct positive integers p1, p2, ..., pcnti (1 ≤ p1 < p2 < ... < pcnti ≤ 106) — the coordinates of points in the i-th query.

It is guaranteed that the total number of points in all queries doesn't exceed 3·105. 

Output

Print m non-negative integers, where the i-th number is the response to the i-th query.

Examples

Input

3 3
1 3
4 5
6 7
3 1 4 7
2 4 5
1 8


Output

3
1
0

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;
public final class valera_and_queries
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static int[][] al,tree;
	static int maxn=(int)(1e6)+4;
	static int[] cnt=new int[maxn];
	
	static void build(int node,int s,int e)
	{
		if(s>e)	
		{
			return;
		}
		if(s==e)
		{
			tree[node]=al[s].clone();
		}
		else
		{
			int mid=(s+e)>>1;
			build(node<<1,s,mid);build(node<<1|1,mid+1,e);
			tree[node]=merge(tree[node<<1],tree[node<<1|1]);
		}
	}
	
	static int[] merge(int[] a,int[] b)
	{
		int i=0,j=0,ptr=0;int[] arr=new int[a.length+b.length];
		while(i<a.length || j<b.length)
		{
			if(i==a.length)
			{
				arr[ptr++]=b[j++];
			}
			else if(j==b.length)
			{
				arr[ptr++]=a[i++];
			}
			else if(a[i]<=b[j])
			{
				arr[ptr++]=a[i++];
			}
			else
			{
				arr[ptr++]=b[j++];
			}
		}
		return arr;
	}
	
	static int searchLast(int[] a,int val)
	{
		int low=0,high=a.length-1;
		while(low<high)
		{
			int mid=(low+high+1)>>1;
			if(a[mid]<=val)
			{
				low=mid;
			}
			else
			{
				high=mid-1;
			}
		}
		return (a.length>0 && a[low]<=val?low+1:0);
	}
	
	static int query(int node,int s,int e,int l,int r,int val)
	{
		if(s>e || l>e || r<s)
		{
			return 0;
		}
		if(l<=s && r>=e)
		{
			return searchLast(tree[node],val);
		}
		else
		{
			int mid=(s+e)>>1;
			return query(node<<1,s,mid,l,r,val)+query(node<<1|1,mid+1,e,l,r,val);
		}
	}
	
    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt(),q=sc.nextInt();Pair[] a=new Pair[n];al=new int[maxn][];tree=new int[4*maxn][];
		for(int i=0;i<n;i++)
		{
			a[i]=new Pair(sc.nextInt(),sc.nextInt());cnt[a[i].l]++;
		}
		Arrays.sort(a);
		for(int i=0;i<maxn;i++)	
		{
			al[i]=new int[cnt[i]];cnt[i]=0;
		}
		for(Pair p:a)
		{
			al[p.l][cnt[p.l]++]=p.r;
		}
		build(1,0,maxn-1);
		while(q>0)
		{
			int k=sc.nextInt();int[] arr=new int[k];
			for(int i=0;i<k;i++)
			{
				arr[i]=sc.nextInt();
			}
			int val=query(1,0,maxn-1,0,arr[0]-1,arr[0]-1)+query(1,0,maxn-1,arr[k-1]+1,maxn-1,maxn-1);
			for(int i=1;i<k;i++)
			{
				val+=query(1,0,maxn-1,arr[i-1]+1,arr[i]-1,arr[i]-1);
			}
			out.println(n-val);q--;
		}
		out.close();
    }
}
class Pair implements Comparable<Pair>
{
	int l,r;
	public Pair(int l,int r)
	{
		this.l=l;this.r=r;
	}
	public int compareTo(Pair x)
	{
		if(this.l==x.l)
		{
			return Integer.compare(this.r,x.r);
		}
		return Integer.compare(this.l,x.l);
	}
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }
	
    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
	
	public String next() throws Exception {
		return nextToken().toString();
	}
	
    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}