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:
/*
 * Author Ayub Subhaniya
 * Institute DA-IICT
 */

import java.io.*;
import java.math.*;
import java.util.*;

public class Driver {

	InputStream in;
	PrintWriter out;
	
	int MAX=1000013;
	int MAX2=1000000;
	
	void solve() {
		int n=ni();
		int m=ni();
		
		Pair segments[]=new Pair[n];
		
		for (int i=0;i<n;i++)
			segments[i]=new Pair(ni(), ni());
		
		
		ArrayList<Integer> query[]=new ArrayList[m];
		for (int i=0;i<m;i++)
		{
			int k=ni();
			query[i]=new ArrayList<Integer>();
			
			for (int j=0;j<k;j++)
				query[i].add(ni());
		}
		
		
		ArrayList<Integer> end[]=new ArrayList[MAX];
		ArrayList<Pair> interval[]=new ArrayList[MAX];
		for (int i=0;i<MAX;i++)
		{
			end[i]=new ArrayList<Integer>();
			interval[i]=new ArrayList<Pair>();
		}
		
		for (int i=0;i<n;i++)
			end[segments[i].y].add(segments[i].x);
		
		for (int i=0;i<m;i++)
		{
			int l=0;
			int r=query[i].get(0)-1;
			interval[r].add(new Pair(l,i));
			
			for (int j=1;j<query[i].size();j++)
			{
				l=query[i].get(j-1)+1;
				r=query[i].get(j)-1;
				interval[r].add(new Pair(l,i));
			}
			
			l=query[i].get(query[i].size()-1)+1;
			r=MAX2;
			interval[r].add(new Pair(l,i));
		}
		
		int ans[]=new int[m];
		FenwickTree ft=new FenwickTree(MAX);
		
		for (int i=0;i<MAX;i++)
		{
			for (int j=0;j<end[i].size();j++)
				ft.update(end[i].get(j));
			
			for (int j=0;j<interval[i].size();j++)
			{
				Pair p=interval[i].get(j);
				ans[p.y]+=ft.query(p.x,i);
			}
		}
		
		for (int i=0;i<m;i++)
			out.println(n-ans[i]);
		
		
		out.close();
	}
	
	class Pair implements Comparable<Pair> {
		int x;
		int y;

		Pair(int a, int b) {
			x = a;
			y = b;
		}

		@Override
		public boolean equals(Object o) {
			Pair other = (Pair) o;
			return x == other.x && y == other.y;
		}

		public String toString() {
			return x + " " + y;
		}

		@Override
		public int compareTo(Pair o) {
			if (y == o.y)
				return Integer.compare(x, o.x);
			else
				return Integer.compare(y, o.y);
		}

		@Override
		public int hashCode() {
			return Objects.hash(x, y);
		}
	}
	
	class FenwickTree {
		int size;
		int bit[];

		FenwickTree(int s) {
			size = s;
			bit = new int[size + 1];

		}

		void update(int x) {
			for (; x <= size; x += x & (-x))
				bit[x] += 1;
		}

		int query(int x) {
			int sum = 0;
			for (; x > 0; x -= x & (-x))
				sum += bit[x];
			return sum;
		}
		
		int query(int l,int r)
		{
			return query(r)-query(l-1);
		}
	}

	
	

	void run() throws Exception {
		String INPUT = "C:/Users/ayubs/Desktop/input.txt";
		in = oj ? System.in : new FileInputStream(INPUT);
		out = new PrintWriter(System.out);

			long s = System.currentTimeMillis();
			solve();
			out.flush();
			tr(System.currentTimeMillis() - s + "ms");
	}

	

	public static void main(String[] args) throws Exception {
		new Driver().run();
	}

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = in.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean inSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && inSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(inSpaceChar(b))) { // when nextLine, (inSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(inSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

	private void tr(Object... o) {
		if (!oj)
			System.out.println(Arrays.deepToString(o));
	}

}