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

public class Main {

    public static final DecimalFormat DF_3 = new DecimalFormat("0.000");


    static int[] readArray(int size, InputReader in, boolean subOne) {
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextInt() + (subOne ? -1 : 0);
        }
        return a;
    }

    static long[] readLongArray(int size, InputReader in) {
        long[] a = new long[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextLong();
        }
        return a;
    }

    static void sortArray(int[] a) {
        Random random = new Random();

        for (int i = 0; i < a.length; i++) {
            int randomPos = random.nextInt(a.length);
            int t = a[i];
            a[i] = a[randomPos];
            a[randomPos] = t;
        }
        Arrays.sort(a);
    }

    private static class TwoPointSegment {

        int left;
        int right;
        int queryNum;

        public TwoPointSegment(int left, int right, int queryNum) {
            this.left = left;
            this.right = right;
            this.queryNum = queryNum;
        }
    }

    static class SegTree {
        private int size;
        private final int[] tree;

        SegTree(int[] a) {
            size = 1;
            while (size < a.length) {
                size *= 2;
            }
            tree = new int[2 * size - 1];

            build(a, 0, 0, size);
        }

        private void build(int[] a, int x, int lx, int rx) {
            if (rx - lx == 1) {
                if (lx < a.length) {
                    tree[x] = a[lx];
                }
            } else {
                int m = (rx + lx) / 2;
                build(a, 2 * x + 1, lx, m);
                build(a, 2 * x + 2, m, rx);
                tree[x] = tree[2 * x + 1] + tree[2 * x + 2];
            }
        }

        public void set(int i, int v) {
            set(i, v, 0, 0, size);
        }

        private void set(int i, int v, int x, int lx, int rx) {
            if (rx - lx == 1) {
                tree[x] = v;
                return;
            }
            int m = (rx + lx) / 2;
            if (i >= m) {
                set(i, v, 2 * x + 2, m, rx);
            } else {
                set(i, v, 2 * x + 1, lx, m);
            }
            tree[x] = tree[2 * x + 1] + tree[2 * x + 2];
        }

        public int result(int l, int r) {
            return result(l, r, 0, 0, size);
        }

        private int result(int l, int r, int x, int lx, int rx) {
            if (l >= rx || lx >= r) {
                return 0;
            }
            if (lx >= l && rx <= r) {
                return tree[x];
            }
            int m = (lx + rx) / 2;
            return result(l, r, 2 * x + 1, lx, m) + result(l, r, 2 * x + 2, m, rx);
        }
    }


    public static void main(String[] args) throws FileNotFoundException {
//        InputReader in = new InputReader(new FileInputStream("input.txt"));
//        PrintWriter out = new PrintWriter(new BufferedOutputStream(new FileOutputStream("milkvisits.out")));
//
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

//        long start = System.currentTimeMillis();


        int n = in.nextInt();
        int m = in.nextInt();

        int[][] segments = new int[n][];
        for (int i = 0; i < n; i++) {
            segments[i] = new int[]{in.nextInt(), in.nextInt()};
        }

        Arrays.sort(segments, Comparator.comparingInt(o -> o[1]));

        List<TwoPointSegment> allPointSegments = new ArrayList<>(m);

        for (int i = 0; i < m; i++) {
            int cnt = in.nextInt();
            int[] points = readArray(cnt, in, false);
            sortArray(points);

            int k = 0;

            while (k < cnt + 1) {
                int leftPoint = k > 0 ? points[k - 1] : Integer.MIN_VALUE;
                int rightPoint = k < cnt ? points[k] : Integer.MAX_VALUE;

                if (rightPoint - leftPoint == 1) {
                    k++;
                    continue;
                }

                TwoPointSegment segment = new TwoPointSegment(leftPoint, rightPoint, i);
                allPointSegments.add(segment);

                k++;

            }

        }

        int[] ans = new int[m];
        int[] lefts = new int[1000001];
        SegTree segTree = new SegTree(lefts);

        allPointSegments.sort(Comparator.comparingInt(o -> o.right));

        int ind = 0;
        for (int i = 0; i < allPointSegments.size(); i++) {
            TwoPointSegment segment = allPointSegments.get(i);
            while (ind < segments.length && segments[ind][1] < segment.right) {
                lefts[segments[ind][0]]++;
                segTree.set(segments[ind][0], lefts[segments[ind][0]]);
                ind++;
            }
            ans[segment.queryNum] += segTree.result(segment.left + 1, segment.right);
        }

        for (int i = 0; i < m; i++) {
            out.println(n - ans[i]);
        }

        out.close();
    }

    private static int findMaxLeft(int nextInd, int rightPoint, int[][] segments) {
        int r = segments.length;
        int l = nextInd - 1;
        while (r - l > 1) {
            int m = (r + l) / 2;
            if (segments[m][0] >= rightPoint) {
                r = m;
            } else {
                l = m;
            }
        }
        return l;
    }

    private static int findMinLeft(int ind, int leftPoint, int[][] segments) {
        int r = segments.length;
        int l = ind - 1;
        while (r - l > 1) {
            int m = (r + l) / 2;
            if (segments[m][0] > leftPoint) {
                r = m;
            } else {
                l = m;
            }
        }
        return r;
    }

    private static void outputArray(long[] ans, PrintWriter out, boolean addOne) {
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < ans.length; i++) {
            long an = ans[i] + (addOne ? 1 : 0);
            str.append(an).append(' ');
        }
        out.println(str);
    }

    private static void outputArray(List<Integer> ans, PrintWriter out, boolean addOne) {
        StringBuilder str = new StringBuilder();
        for (int j = 0; j < ans.size(); j++) {
            long i = ans.get(j);
            long an = i + (addOne ? 1 : 0);
            str.append(an);
            if (j < ans.size() - 1) {
                str.append(' ');
            }
        }
        out.println(str);
//        out.flush();
    }

    private static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextString() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextWord() {
            return next();
        }

        private List<Integer>[] readTree(int n) {
            return readGraph(n, n - 1);
        }

        private List<Integer>[] readGraph(int n, int m) {
            List<Integer>[] result = new ArrayList[n];
            for (int i = 0; i < n; i++) {
                result[i] = new ArrayList<>();
            }
            for (int i = 0; i < m; i++) {
                int u = nextInt() - 1;
                int v = nextInt() - 1;
                result[u].add(v);
                result[v].add(u);
            }
            return result;
        }

    }
}