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;
const int maxn = 2e6;
pair<int, int> segs[maxn];
int lsorted[maxn];
int rsorted[maxn];
int lsrtdidx[maxn];
vector<int> questions[maxn];
pair<int, int> queries[maxn];
int ansqrs[maxn];
vector<int> qs_qr_idxs[maxn];
vector<int> qrsendinginR[maxn];
vector<int> segsendinginR[maxn];
int vals[maxn];
int N;
int qrcnt = 0;
inline int add_qr(int x, int y) {
  queries[qrcnt] = {x, y};
  return qrcnt++;
}
void turnon(int p, int l, int r, int v) {
  if (r <= l) return;
  if (p < l or p >= r) return;
  if (r - l == 1) {
    vals[v] = 1;
    return;
  }
  int m = (l + r) / 2;
  turnon(p, l, m, 2 * v);
  turnon(p, m, r, 2 * v + 1);
  vals[v] = vals[2 * v] + vals[2 * v + 1];
}
int get(int l, int r, int s, int e, int v) {
  if (r <= l) return 0;
  if (e <= l or r <= s) return 0;
  if (s <= l and r <= e) return vals[v];
  int m = (l + r) / 2;
  return get(l, m, s, e, 2 * v) + get(m, r, s, e, 2 * v + 1);
}
inline int bins(int x) {
  int down = -1;
  int up = N;
  while (up - down > 1) {
    int mid = (up + down) / 2;
    if (segs[lsorted[mid]].first < x)
      down = mid;
    else
      up = mid;
  }
  return up;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  N = n;
  for (int i = 0; i < n; i++) cin >> segs[i].first >> segs[i].second;
  for (int i = 0; i < n; i++) lsorted[i] = rsorted[i] = i;
  sort(lsorted, lsorted + n,
       [&](int i, int j) { return segs[i].first < segs[j].first; });
  sort(rsorted, rsorted + n,
       [&](int i, int j) { return segs[i].second < segs[j].second; });
  for (int i = 0; i < n; i++) lsrtdidx[lsorted[i]] = i;
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    questions[i] = vector<int>(k);
    for (int j = 0; j < k; j++) cin >> questions[i][j];
    int last = 0;
    for (int j = 0; j < k; j++) {
      int cur = questions[i][j];
      qs_qr_idxs[i].push_back(add_qr(last + 1, cur));
      last = cur;
    }
    qs_qr_idxs[i].push_back(add_qr(last + 1, maxn - 1));
  }
  for (int i = 0; i < qrcnt; i++) qrsendinginR[queries[i].second].push_back(i);
  for (int i = 0; i < n; i++) segsendinginR[segs[i].second].push_back(i);
  for (int i = 0; i < maxn; i++) {
    for (int j : qrsendinginR[i]) {
      int ql = queries[j].first;
      int qr = i;
      int l = bins(ql);
      int r = bins(qr);
      ansqrs[j] = get(0, n, l, r, 1);
    }
    for (int j : segsendinginR[i]) {
      turnon(lsrtdidx[j], 0, n, 1);
    }
  }
  for (int i = 0; i < m; i++) {
    int a = 0;
    for (int j : qs_qr_idxs[i]) a += ansqrs[j];
    cout << n - a << endl;
  }
  return 0;
}