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.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Set;

public class ValeraAndQueries {
	static InputReader in;
	static PrintWriter out;
	public static void main(String[] args) throws Exception {
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);
	
		int n = in.nextInt();
		int m = in.nextInt();
		
		Segment[] sourceSegments = new Segment[n];
		for(int i=0;i<n;i++) {
			sourceSegments[i] = new Segment(in.nextInt(), in.nextInt());
		}
		
		List<Integer>[] queries = new List[m];
		for(int i=0;i<m;i++){
			int sz = in.nextInt();
			queries[i] = new ArrayList();
			for(int j=0;j<sz;j++) {
				queries[i].add(in.nextInt());
			}
		}
		
		List<Segment> qs = new ArrayList();
		for(int i = 0; i < m; i++) {
			int l = 0;
			for(int p : queries[i]) {
				Segment s = new Segment(l, p);
				s.id = i;
				l = p + 1;
				qs.add(s);
			}
		}
		
		Collections.sort(qs);
		Arrays.sort(sourceSegments);
		
		int[] ans = new int[m];
		
		// at the start of iteration, when processing q=querySegment[i]  
		// bit[i] = number of sourceSegments with r >= q.r & l = i
		Fenwick1 bit = new Fenwick1(1000005);
		int si = 0;
		for(Segment s : qs) {
			int qr = s.r;
			while(si < sourceSegments.length) {
				Segment source = sourceSegments[si];
				if(source.r >= qr) {
					bit.increment(source.l, 1);
					si++;
				}else{
					break;
				}
			}
			
			ans[s.id] += bit.querySum(s.r) - bit.querySum(s.l-1);
		}
		
		for(int i : ans) {
			out.println(i);
		}
		
		out.close();
	}

	static class Fenwick1 {
		long[] tree;
		public Fenwick1(int n) {
			tree = new long[n+1];
		}
		
		public void increment(int i, int v) {
			while(i < tree.length) {
				tree[i] += v;
				i += (i & -i);
			}
		}
		
		public int querySum(int i) {
			int sum = 0;
			while(i > 0) {
				sum += tree[i];
				i -= (i & -i);
			}
			return sum;
		}
	}
	
	static class Segment implements Comparable<Segment>{
		public int l;
		public int r;
		public int id;
		
		public Segment(int l, int r) {
			this.l = l;
			this.r = r;
		}
		
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + l;
			result = prime * result + r;
			return result;
		}
		
		@Override
		public boolean equals(Object obj) {
			Segment other = (Segment) obj;
			if (l != other.l)
				return false;
			if (r != other.r)
				return false;
			return true;
		}

		@Override
		public int compareTo(Segment o) {
			return o.r - this.r;
		}
	}
	
	static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}
		
		
		public 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++];
		}

		public 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;
		}

		public 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;
		}
		

		public 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();
		}

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

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

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