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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int treeArr[1048576];
int result[524288];
int resLoc[524288];
struct QueryNode {
  int loc;
  int id;
  bool operator<(const QueryNode other) const { return loc < other.loc; }
  void read(int v_id) {
    scanf("%d", &loc);
    id = v_id;
  }
} queryNodes[524288];
int qlen;
int mxRgt;
struct PairNode {
  bool lr;
  int pos;
  int belong;
  bool operator<(const PairNode other) const {
    if (pos != other.pos)
      return pos < other.pos;
    else
      return lr || (!other.lr);
  }
  void set(int v_pos, bool v_lr, int v_belong) {
    pos = v_pos;
    lr = v_lr;
    belong = v_belong;
    if (lr == false && pos > mxRgt) mxRgt = pos;
  }
} pairNodes[524288 << 1];
struct Pair {
  int left, right;
  void read(int i);
} pairs[524288];
void Pair::read(int i) {
  scanf("%d%d", &pairs[i].left, &pairs[i].right);
  pairNodes[i * 2].set(left, true, i);
  pairNodes[i * 2 + 1].set(right, false, i);
}
void add(int pos) {
  while (pos <= mxRgt) {
    treeArr[pos]++;
    pos += (pos & (-pos));
  }
}
void sub(int pos) {
  while (pos <= mxRgt) {
    treeArr[pos]--;
    pos += (pos & (-pos));
  }
}
int sum(int pos) {
  int rtn = 0;
  while (pos) {
    rtn += treeArr[pos];
    pos -= (pos & (-pos));
  }
  return rtn;
}
void getResult(int j) {
  if (resLoc[queryNodes[j].id] == -1) {
    result[queryNodes[j].id] = sum(queryNodes[j].loc);
    resLoc[queryNodes[j].id] = queryNodes[j].loc;
  } else {
    result[queryNodes[j].id] +=
        sum(queryNodes[j].loc) - sum(resLoc[queryNodes[j].id]);
    resLoc[queryNodes[j].id] = queryNodes[j].loc;
  }
}
void solve(int n) {
  int i, j;
  i = j = 0;
  while (i < n && j < qlen) {
    if (pairNodes[i].pos < queryNodes[j].loc ||
        pairNodes[i].pos == queryNodes[j].loc && pairNodes[i].lr) {
      pairNodes[i].lr ? add(pairNodes[i].pos)
                      : sub(pairs[pairNodes[i].belong].left);
      i++;
    } else {
      getResult(j++);
    }
  }
  while (j < qlen) {
    getResult(j++);
  }
}
void output(int m) {
  int i;
  for (i = 0; i < m; i++) {
    printf("%d\n", result[i]);
  }
}
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    int cnt, i, j;
    mxRgt = 0;
    for (i = 0; i < n; i++) {
      pairs[i].read(i);
    }
    sort(pairNodes, pairNodes + n * 2);
    for (j = 0; j < m; j++) {
      scanf("%d", &cnt);
      for (i = 0; i < cnt; i++) {
        queryNodes[qlen++].read(j);
      }
    }
    sort(queryNodes, queryNodes + qlen);
    memset(treeArr, 0, sizeof(treeArr));
    memset(resLoc, -1, sizeof(resLoc));
    solve(n << 1);
    output(m);
  }
  return 0;
}