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

public class Main
{
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;
	private PrintWriter pw;
	private long mod = 1000000000;
	
	private StringBuilder ans_sb;
	private static int block;
	private void soln()
	{	
		int n = nextInt();
		int m = nextInt();
		LinkedList<Integer>[] list = new LinkedList[1000002];
		for(int i=0;i<=1000001;i++)
			list[i] = new LinkedList<>();
		int max = -1;
		for(int i=0;i<n;i++) {
			int l = nextInt() - 1;
			int r = nextInt() - 1;
			list[r].add(0,l);
			max = Math.max(max, r);
		}
		LinkedList<Pair>[] sl = new LinkedList[max+2];
		for(int i=0;i<=max+1;i++)
			sl[i] = new LinkedList<>();
		for(int i=0;i<m;i++) {
			int cnt = nextInt();
			int st = 0;
			for(int j=0;j<cnt;j++) {
				int p = nextInt() - 1;
				if(p>max+1)
					continue;
				sl[p].add(0, new Pair(st,i));
				st = p+1;
			}
			sl[max+1].add(new Pair(st,i));
		}
		Segment tree = new Segment(max+2);
		int[] ans = new int[m];
		for(int i=0;i<=max+1;i++) {
			for(Pair p:sl[i]) {
				ans[p.idx] += tree.query(p.st, i);
				//debug(p);
				//System.out.println(i+" "+ans[p.idx]);
			}
			for(int x:list[i]) {
				tree.update(x, x, 1);
				//System.out.println(tree.query(0, 1000000));
			}
		}
		for(int i=0;i<m;i++)
			pw.println(n-ans[i]);
	}
	private class Pair implements Comparable<Pair>{
		int st;
		int idx;
		public Pair(int a,int b) {
			st = a;
			idx = b;
		}
		@Override
		public int compareTo(Pair o)
		{
			return this.idx - o.idx;
		}
		public String toString() {
			return (this.st)+" "+(this.idx);
		}
	}

	public class Segment
	{
		private int[] tree;
		private boolean[] lazy;
		private int size;
		private int n;

		private class Node
		{
			private int l;
			private int r;
			private long ans;
			private long ans2;
		}

		public Segment(int n)
		{
			// this.base=arr;
			int x = (int) (Math.ceil(Math.log(n) / Math.log(2)));
			size = 2 * (int) Math.pow(2, x) - 1;
			tree = new int[size];
		//	lazy = new boolean[size];
			this.n = n;
			//this.set = set1;
			//build(0, 0, n - 1);
		}

		
		public Node merge(Node n1, Node n2, int l, int r) {
			Node ret = new Node();
			if(n1 == null && n2 == null)
				return null;
			else if(n1 == null) {
				ret.ans = n2.ans;
				ret.l = n2.l;
				ret.r = n2.r;
			}
			
			else if(n2 == null) {
				ret.ans = n1.ans;
				ret.l = n1.l;
				ret.r = n1.r;
			}
			else {
				ret.l = n1.l;
				ret.r = n2.r;
				ret.ans = n1.ans + n2.ans;
				//long diff = n2.l - n1.r - 1;
				//ret.ans += (diff*(diff+1))/2;
			}
			
			return ret;
		}
		public int query(int l, int r)
		{
			
				return queryUtil(l,r,0,0,n-1);
		}

		private int queryUtil(int x, int y, int id, int l, int r)
		{
			if (l > y || x > r)
				return 0;
			if (x <= l && r <= y)
			{
				return tree[id];
			}
			int mid = l + (r - l) / 2;
			// shift(id);
			int q1 = queryUtil(x, y, 2 * id + 1, l, mid);
			int q2 = queryUtil(x, y, 2 * id + 2, mid + 1, r);

			return q1+q2;
		}
		
		public void update(int x, int y, int c) {
			update1(x, y, c, 0, 0, n-1);
		}
		
		private void update1(int x, int y, int colour, int id, int l, int r)
		{
			//System.out.println(l+" "+r+" "+x);
			if (x > r || y < l)
				return;
			if (x <= l && r <= y)
			{
				if(colour!=-1) {
					tree[id]++;
				}
				return;
			}
			int mid = l + (r - l) / 2;
			// shift(id);
			if(y<=mid)
				update1(x, y, colour, 2 * id + 1, l, mid);
			else if(x>mid)
				update1(x, y, colour, 2 * id + 2, mid + 1, r);
			else {
				update1(x, y, colour, 2 * id + 1, l, mid);
				update1(x, y, colour, 2 * id + 2, mid + 1, r);
			}
			tree[id] = (tree[2*id+1]+ tree[2*id+2]);
			
		}
		
	}

	private String solveEqn(long a, long b) {
        long x = 0, y = 1, lastx = 1, lasty = 0, temp;
        while (b != 0){
        	long q = a / b;
        	long r = a % b;
            a = b;
            b = r;
            temp = x;
            x = lastx - q * x;
            lastx = temp;
            temp = y;
            y = lasty - q * y;
            lasty = temp;
        }
        return lastx+" "+lasty;
	}
//	private class Node implements Comparable<Node>{
//		Dint node;
//		int dist;
//
//		@Override
//		public int compareTo(Node arg0)
//		{
//			if(this.dist != arg0.dist)
//				return (int) (this.dist - arg0.dist);
//			return this.node - arg0.node;
//		}
//		public boolean equals(Object o){
//			if(o instanceof Node){
//				Node c = (Node)o;
//				return this.node == c.node && this.dist == c.dist;
//			}
//			return false;
//		}
//		public String toString() {
//			return this.node+", "+this.dist;
//		}
//	}
	
	private void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
	
	private long pow(long a, long b, long c)
	{
		if (b == 0)
			return 1;
		long p = pow(a, b / 2, c);
		p = (p * p) % c;
		return (b % 2 == 0) ? p : (a * p) % c;
	}

	private long gcd(long n, long l)
	{
		if (l == 0)
			return n;
		return gcd(l, n % l);
	}
	public static void main(String[] args) throws Exception
	{
		new Thread(null, new Runnable()
		{
			@Override
			public void run()
			{
				new Main().solve();
			}
		}, "1", 1 << 26).start();
	}
	public StringBuilder solve(){
		InputReader(System.in);
		/*try { 
			InputReader(new FileInputStream("C:\\Users\\hardik\\Desktop\\in.txt"));
		} catch(FileNotFoundException e) {}
		*/
		pw = new PrintWriter(System.out);
		ans_sb = new StringBuilder();
		soln();
		
		pw.close();
		//System.out.println(ans_sb);
		return ans_sb;
	}
	public void InputReader(InputStream stream1)
	{
		stream = stream1;
	}

	private boolean isWhitespace(int c)
	{
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private boolean isEndOfLine(int c)
	{
		return c == '\n' || c == '\r' || c == -1;
	}

	private int read()
	{
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars)
		{
			curChar = 0;
			try
			{
				numChars = stream.read(buf);
			} catch (IOException e)
			{
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	private int nextInt()
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-')
		{
			sgn = -1;
			c = read();
		}
		int res = 0;
		do
		{
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private long nextLong()
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-')
		{
			sgn = -1;
			c = read();
		}
		long res = 0;
		do
		{
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private String nextToken()
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do
		{
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private String nextLine()
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do
		{
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	private int[] nextIntArray(int n)
	{
		int[] arr = new int[n];
		for (int i = 0; i < n; i++)
		{
			arr[i] = nextInt();
		}
		return arr;
	}

	private long[] nextLongArray(int n)
	{
		long[] arr = new long[n];
		for (int i = 0; i < n; i++)
		{
			arr[i] = nextLong();
		}
		return arr;
	}

	private void pArray(int[] arr)
	{
		for (int i = 0; i < arr.length; i++)
		{
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private void pArray(long[] arr)
	{
		for (int i = 0; i < arr.length; i++)
		{
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private boolean isSpaceChar(int c)
	{
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	private char nextChar()
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		char c1 = (char) c;
		while (!isSpaceChar(c))
			c = read();
		return c1;
	}

	private interface SpaceCharFilter
	{
		public boolean isSpaceChar(int ch);
	}
}