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.util.*;
import java.io.*;

public class IntervalQueries {
	public static void main(String[] args) throws IOException {
		BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(rd.readLine());
		n = Integer.parseInt(st.nextToken());
		m = Integer.parseInt(st.nextToken());
		startAt = new ArrayList[1000001];
		for(int i=0; i<startAt.length; i++) startAt[i] = new ArrayList<Interval>();
		for(int i=0; i<n; i++){
			st = new StringTokenizer(rd.readLine());
			int x = Integer.parseInt(st.nextToken()), y = Integer.parseInt(st.nextToken());
			Interval seg = new Interval(x, y, i);
			startAt[x].add(seg);
		}
		queries = new String[m];
		list = new ArrayList[m];
		int queryId = 0;
		int INF = 1000001;
		int[] array = new int[INF];
		for(int i=0; i<m; i++){
			list[i] = new ArrayList<Integer>();
			String line = rd.readLine();
			st = new StringTokenizer(line);
			int cnt = Integer.parseInt(st.nextToken());
			for(int j=0; j<cnt; j++){
				int cur = Integer.parseInt(st.nextToken());
				array[j] = cur;
			}
			if(array[0]>1){
				queriesList.add(new Query(0, array[0]-1, queryId++));
				list[i].add(queryId-1);
			}
			for(int x=0; x<cnt-1; x++){
				if(array[x]+1<=array[x+1]-1){
					queriesList.add(new Query(array[x]+1, array[x+1]-1, queryId++));
					list[i].add(queryId-1);
				}
			}
			queriesList.add(new Query(array[cnt-1]+1, INF, queryId++));
			list[i].add(queryId-1);
		}
		Collections.sort(queriesList, Query.compareQueries);
		int foundAfter = 1000001;
		for(int i=0; i<queriesList.size(); i++){
			Query q = queriesList.get(i);
			// q.from <= foundAfter
			for(int L=foundAfter-1; L>=q.from; L--){
				updateForStartingIndex(L);
			}
			foundAfter = q.from;
			int ansForQuery = getSum(1, 0, 1000001, q.from, q.to);
		//	System.out.println("answer for "+q.from+", "+q.to+" = "+ansForQuery);
			ans[q.id] = ansForQuery;
		}
		for(int i=0; i<m; i++){
			int answer = n;
			for(int x : list[i]){
				answer -= ans[x];
			}
			pw.println(answer);
		}
		pw.flush();
	}
	
	
	static void updateForStartingIndex(int L) {
		ArrayList<Interval> starting = startAt[L];
		for(Interval interval : starting) {
			int rightEnd = interval.r;
			increment(rightEnd);
		}
	}
	
	static void increment(int pos){
		update(1, 0, 1000001, pos, 1);
	}
	
	static int[] T = new int[4000001];
	
	static int getSum(int v, int l, int r, int a, int b){
	//	System.out.println(l+" "+r+" "+a+" "+b);
		if(a>b) return 0;
		if(a==l && b==r){
			return T[v];
		}
		int m = (l+r)>>1;
		if(b<=m) return getSum(2*v, l, m, a, b);
		if(a>m) return getSum(2*v+1, m+1, r, a, b);
		return getSum(2*v, l, m, a, m) + getSum(2*v+1, m+1, r, m+1, b);
	}
	
	static void update(int v, int l, int r, int pos, int delta){
		if(l==r){
			T[v] += delta;
			return;
		}
		int m = (l+r)>>1;
		if(pos<=m) update(2*v, l, m, pos, delta);
		else update(2*v+1, m+1, r, pos, delta);
		T[v] = T[2*v] + T[2*v+1];
	}
	
	static int[] ans = new int[2000000];
	
	static ArrayList<Interval>[] startAt;
	
	static ArrayList<Query> queriesList = new ArrayList<Query>();
	
	static ArrayList<Integer>[] list;
	
	static String[] queries;
	
	static int n, m;
	
}

class Interval {
	public int l, r, id;
	
	public Interval(int l, int r, int id){
		this.l = l;
		this.r = r;
		this.id = id;
	}
	
}

class Query {
	public int from, to, id;
	
	public Query(int from, int to, int id){
		this.from = from;
		this.to = to;
		this.id = id;
	}
	
	public static Comparator<Query> compareQueries = new Comparator<Query>() {
		
		@Override
		public int compare(Query o1, Query o2) {
			return o1.from!=o2.from ? o2.from-o1.from : (o1.id-o2.id);
		}
	};
	
}