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

public class Main {

	static long sx = 0, sy = 0, m = (long) (1e9 + 7);

	static ArrayList<Integer>[] a;
	static long[][] dp;
	static long[] farr;
	static boolean b = true;
	static HashMap<Long, Integer> hm = new HashMap<>();
	static ArrayList<Integer> p = new ArrayList<>();
	public static PrintWriter out;
	static ArrayList<pair> ans = new ArrayList<>();

	public static void main(String[] args) throws IOException {

		Reader scn = new Reader();
        out = new PrintWriter(System.out);
        
		// Scanner scn = new Scanner(System.in);

		int n = scn.nextInt(), m = scn.nextInt();

		ArrayList<pair> p = new ArrayList<>();

		for (int i = 0; i < n; i++) {

			p.add(new pair(scn.nextInt(), scn.nextInt()));
		}

		Collections.sort(p);

		int[] l = new int[p.size()];
		int[] r = new int[p.size()];

		for (int i = 0; i < p.size(); i++) {
			l[i] = p.get(i).l;
			r[i] = p.get(i).r;

		}

		segment st = new segment(r);

		while (m-- != 0) {

			int x = scn.nextInt();

			int[] q = new int[x];

			for (int i = 0; i < x; i++)
				q[i] = scn.nextInt();

			Arrays.parallelSort(q);

			int prev = 0;

			int ans = 0;

			for (int i = 0; i < x; i++) {

				int left = left(prev, l, q[i]);

				if (left == -1)
					continue;

				ans += st.query(prev, left, q[i]);
				prev = left + 1;

				
			}
			out.println(ans);

		}
		out.close();
	}

	public static int left(int prev, int[] a, int val) {

		if (val >= a[a.length - 1])
			return a.length - 1;

		if (val < a[0])
			return -1;

		int lo = prev, hi = a.length - 1, ans = -1;

		while (lo <= hi) {

			int mid = (lo + hi) / 2;

			if (a[mid] <= val) {
				ans = mid;
				lo = mid + 1;
			}

			else
				hi = mid - 1;
		}

		return ans;
	}

	private static class segment {

		private static class node {

			int[] a;
			int si;
			int ei;
			node left, right;
		}

		node root;

		public segment(int[] a) {

			root = Construct(a, 0, a.length - 1);
		}

		private node Construct(int[] a, int si, int ei) {

			if (si == ei) {
				node bn = new node();
				bn.si = si;
				bn.ei = ei;

				int[] ba = { a[si] };
				bn.a = ba;
				return bn;
			}

			node n = new node();
			int mid = (si + ei) / 2;
			n.si = si;
			n.ei = ei;
			n.left = Construct(a, si, mid);
			n.right = Construct(a, mid + 1, ei);
			n.a = merge(n.left.a, n.right.a);

			return n;
		}

		public int query(int si, int ei, int k) {

			return query(root, si, ei, k);
		}

		private int query(node n, int si, int ei, int k) {

			if (n.si >= si && n.ei <= ei) {
				return count(n.a, k);
			}

			else if (n.si > ei || n.ei < si)
				return 0;

			else {

				return query(n.left, si, ei, k) + query(n.right, si, ei, k);
			}

		}

		private int count(int[] a, int k) {

			if (a[0] >= k)
				return a.length;

			if (k > a[a.length - 1])
				return 0;

			if (a.length == 1) {

				if (a[0] >= k)
					return 1;
				return 0;
			}

			int lo = 0, hi = a.length - 1;
			int ans = 0;

			while (lo <= hi) {

				int mid = (lo + hi) / 2;

				if (a[mid] < k) {

					ans = mid;
					lo = mid + 1;
				}

				else
					hi = mid - 1;
			}

			return (a.length - 1) - (ans + 1) + 1;
		}

		private int[] merge(int[] a, int[] b) {

			int[] c = new int[a.length + b.length];

			int i = 0, j = 0, k = 0;

			while (i < a.length && j < b.length) {

				if (a[i] < b[j])
					c[k++] = a[i++];
				else
					c[k++] = b[j++];
			}

			while (i < a.length)
				c[k++] = a[i++];

			while (j < b.length)
				c[k++] = b[j++];
			return c;
		}
	}
	// _________________________TEMPLATE_____________________________________________________________

	// private static int gcd(int a, int b) {
	// if(a== 0)
	// return b;
	//
	// return gcd(b%a,a);
	// }

	// static class comp implements Comparator<pair> {
	//
	// @Override
	// public int compare(pair o1, pair o2) {
	//
	// return (int) (o1.y - o1.y);
	// }
	//
	// }

	private static class pair implements Comparable<pair> {

		int l, r;

		pair(int a, int b) {
			l = a;
			r = b;
		}

		@Override
		public int compareTo(pair o) {

			if (this.l != o.l)
				return this.l - o.l;

			else
				return this.r - o.r;
		}

	}

	public static class Reader {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException {
			byte[] buf = new byte[1000000 + 1]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}

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

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

		public int[][] nextInt2DArray(int m, int n) throws IOException {
			int[][] arr = new int[m][n];
			for (int i = 0; i < m; i++) {
				for (int j = 0; j < n; j++)
					arr[i][j] = nextInt();
			}
			return arr;
		}
		// kickstart - Solution
		// atcoder - Main
	}

}