#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
int l[N], r[N], p[N];
int c;
vector<int> queries[N];
struct node {
  node *l, *r;
  int val;
  node() : l(NULL), r(NULL), val(0) {}
} * version[N];
int getval(node *&cur) {
  if (!cur) return 0;
  return cur->val;
}
node *gl(node *&prev) {
  if (!prev) return NULL;
  return prev->l;
}
node *gr(node *&prev) {
  if (!prev) return NULL;
  return prev->r;
}
void update(node *&cur, node *prev, int s, int e, int idx) {
  if (!cur) cur = new node();
  cur->val = getval(prev) + 1;
  if (s == e) return;
  int m = (s + e) >> 1;
  if (idx <= m) {
    update(cur->l, gl(prev), s, m, idx);
    cur->r = gr(prev);
  } else {
    update(cur->r, gr(prev), m + 1, e, idx);
    cur->l = gl(prev);
  }
}
int query(node *&cur, int s, int e, int l, int r) {
  if (s > r || e < l || !cur) return 0;
  if (l <= s && e <= r) return cur->val;
  int m = (s + e) >> 1;
  return query(cur->l, s, m, l, r) + query(cur->r, m + 1, e, l, r);
}
int query(int l, int r) {
  if (l > r) return 0;
  int ans =
      query(version[p[r]], 1, N, 1, r) - query(version[p[l - 1]], 1, N, 1, r);
  return ans;
}
signed main() {
  ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> l[i] >> r[i];
    queries[l[i]].push_back(r[i]);
  }
  for (int i = 1; i <= N - 1; i++) {
    for (int x : queries[i]) {
      update(version[c + 1], version[c], 1, N, x);
      c++;
    }
    p[i] = c;
  }
  for (int i = 1; i <= m; i++) {
    int ans = n;
    int k;
    cin >> k;
    int last = 1;
    for (int j = 1; j <= k; j++) {
      int x;
      cin >> x;
      ans -= query(last, x - 1);
      last = x + 1;
    }
    ans -= query(last, N - 1);
    cout << ans << endl;
  }
  return 0;
}

### Prompt

Construct a CPP code solution to the problem outlined:

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
int l[N], r[N], p[N];
int c;
vector<int> queries[N];
struct node {
  node *l, *r;
  int val;
  node() : l(NULL), r(NULL), val(0) {}
} * version[N];
int getval(node *&cur) {
  if (!cur) return 0;
  return cur->val;
}
node *gl(node *&prev) {
  if (!prev) return NULL;
  return prev->l;
}
node *gr(node *&prev) {
  if (!prev) return NULL;
  return prev->r;
}
void update(node *&cur, node *prev, int s, int e, int idx) {
  if (!cur) cur = new node();
  cur->val = getval(prev) + 1;
  if (s == e) return;
  int m = (s + e) >> 1;
  if (idx <= m) {
    update(cur->l, gl(prev), s, m, idx);
    cur->r = gr(prev);
  } else {
    update(cur->r, gr(prev), m + 1, e, idx);
    cur->l = gl(prev);
  }
}
int query(node *&cur, int s, int e, int l, int r) {
  if (s > r || e < l || !cur) return 0;
  if (l <= s && e <= r) return cur->val;
  int m = (s + e) >> 1;
  return query(cur->l, s, m, l, r) + query(cur->r, m + 1, e, l, r);
}
int query(int l, int r) {
  if (l > r) return 0;
  int ans =
      query(version[p[r]], 1, N, 1, r) - query(version[p[l - 1]], 1, N, 1, r);
  return ans;
}
signed main() {
  ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> l[i] >> r[i];
    queries[l[i]].push_back(r[i]);
  }
  for (int i = 1; i <= N - 1; i++) {
    for (int x : queries[i]) {
      update(version[c + 1], version[c], 1, N, x);
      c++;
    }
    p[i] = c;
  }
  for (int i = 1; i <= m; i++) {
    int ans = n;
    int k;
    cin >> k;
    int last = 1;
    for (int j = 1; j <= k; j++) {
      int x;
      cin >> x;
      ans -= query(last, x - 1);
      last = x + 1;
    }
    ans -= query(last, N - 1);
    cout << ans << endl;
  }
  return 0;
}

```