#include <bits/stdc++.h>
std::mt19937_64 rng(
    std::chrono::steady_clock::now().time_since_epoch().count());
long long int myRand(long long int R) {
  long long int val = rng() % R;
  assert(val >= 0);
  return val;
}
const long double PI = atan(1.0) * 4;
const int32_t INF32 = 2e9 + 7;
const int64_t INF64 = 3e18;
const int32_t LOG = 21;
int32_t MOD = 1e9 + 7;
using namespace std;
void my_debugger(string second, long long int LINE_NUM) { cerr << '\n'; }
template <typename start, typename... end>
void my_debugger(string second, long long int LINE_NUM, start x, end... y) {
  if (second.back() != ',') {
    second += ',';
    cerr << "LINE(" << LINE_NUM << "): ";
  }
  long long int i = second.find(',');
  cerr << second.substr(0, i) << " = " << x;
  second = second.substr(i + 1);
  if (!second.empty()) cerr << ", ";
  my_debugger(second, LINE_NUM, y...);
}
struct segtree {
  vector<long long int> t;
  long long int n;
  segtree(long long int n) : n(n), t(4 * n + 6) {}
  void update(long long int i, long long int tl, long long int tr,
              long long int ind, long long int val) {
    if (tl == tr) {
      t[i] += val;
      return;
    }
    long long int tmid = (tl + tr) >> 1;
    if (ind <= tmid)
      update(2 * i, tl, tmid, ind, val);
    else
      update(2 * i + 1, tmid + 1, tr, ind, val);
    t[i] = t[2 * i] + t[2 * i + 1];
  }
  void update(long long int ind, long long int val) {
    update(1, 1, n, ind, val);
  }
  long long int query(long long int i, long long int tl, long long int tr,
                      long long int l, long long int r) {
    if (l > r) return 0;
    if (l <= tl && tr <= r) return t[i];
    long long int tmid = (tl + tr) >> 1;
    return query(2 * i, tl, tmid, l, min(r, tmid)) +
           query(2 * i + 1, tmid + 1, tr, max(l, tmid + 1), r);
  }
  long long int query(long long int l, long long int r) {
    return query(1, 1, n, l, r);
  }
};
long long int ans[3000005];
vector<long long int> v[1000005];
vector<long long int> v1[1000005];
vector<long long int> v2[1000005];
long long int start[3000005];
long long int start1[3000005];
long long int end1[3000005];
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  long long int tests = 1;
  for (long long int ii = 0; ii < (long long int)tests; ii++) {
    long long int n, m;
    cin >> n >> m;
    long long int BIG = 1e6;
    long long int cur = 1;
    for (long long int i = 1; i < (long long int)n + 1; i++) {
      long long int l, r;
      cin >> l >> r;
      v[l].push_back(cur);
      v[r].push_back(cur);
      v2[l].push_back(cur);
      v2[r].push_back(cur);
      end1[cur] = r;
      cur++;
    }
    vector<pair<long long int, vector<long long int>>> input;
    for (long long int i = 1; i < (long long int)m + 1; i++) {
      long long int cnt;
      cin >> cnt;
      vector<long long int> vals(cnt);
      for (long long int j = 0; j < (long long int)cnt; j++) cin >> vals[j];
      long long int l = vals[0], r = vals.back();
      v1[l].push_back(cur);
      v1[r].push_back(cur);
      v2[l].push_back(-cur);
      end1[cur] = r;
      cur++;
      long long int temp = cur - 1;
      vector<long long int> temp1;
      long long int prev = vals[0];
      for (long long int j = 1; j < (long long int)cnt; j++) {
        long long int now = vals[j];
        if (prev + 1 <= now - 1) {
          v[prev + 1].push_back(-cur);
          v[now - 1].push_back(-cur);
          temp1.push_back(cur);
          cur++;
        }
        prev = now;
      }
      input.push_back({temp, temp1});
    }
    segtree seg(BIG), seg1(BIG), seg2(BIG);
    for (long long int i = 1; i < (long long int)BIG + 1; i++) {
      sort(v[i].rbegin(), v[i].rend());
      for (auto it : v[i]) {
        if (it < 0) {
          if (!start[-it])
            start[-it] = i;
          else
            ans[-it] = seg.query(start[-it], i);
        } else {
          if (!start[it]) {
            start[it] = i;
            seg1.update(i, 1);
          } else {
            seg.update(start[it], 1);
            seg1.update(start[it], -1);
            seg1.update(i, 1);
          }
        }
      }
      for (auto it : v1[i]) {
        if (!start[it])
          start[it] = i;
        else
          ans[it] = seg1.query(start[it], i);
      }
    }
    for (long long int i = 1; i < (long long int)BIG + 1; i++) {
      sort(v2[i].begin(), v2[i].end());
      for (auto it : v2[i]) {
        if (it < 0) {
          it = -it;
          ans[it] += seg2.query(end1[it] + 1, BIG);
        } else {
          if (!start1[it]) {
            start1[it] = i;
            seg2.update(end1[it], 1);
          } else
            seg2.update(i, -1);
        }
      }
    }
    for (auto& it : input) {
      long long int val1 = it.first;
      vector<long long int>& vals = it.second;
      long long int sol = ans[val1];
      for (long long int x : vals) sol -= ans[x];
      cout << sol << '\n';
    }
  }
  return 0;
}

### Prompt

Please create a solution in Cpp to the following 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

### Response

```cpp
#include <bits/stdc++.h>
std::mt19937_64 rng(
    std::chrono::steady_clock::now().time_since_epoch().count());
long long int myRand(long long int R) {
  long long int val = rng() % R;
  assert(val >= 0);
  return val;
}
const long double PI = atan(1.0) * 4;
const int32_t INF32 = 2e9 + 7;
const int64_t INF64 = 3e18;
const int32_t LOG = 21;
int32_t MOD = 1e9 + 7;
using namespace std;
void my_debugger(string second, long long int LINE_NUM) { cerr << '\n'; }
template <typename start, typename... end>
void my_debugger(string second, long long int LINE_NUM, start x, end... y) {
  if (second.back() != ',') {
    second += ',';
    cerr << "LINE(" << LINE_NUM << "): ";
  }
  long long int i = second.find(',');
  cerr << second.substr(0, i) << " = " << x;
  second = second.substr(i + 1);
  if (!second.empty()) cerr << ", ";
  my_debugger(second, LINE_NUM, y...);
}
struct segtree {
  vector<long long int> t;
  long long int n;
  segtree(long long int n) : n(n), t(4 * n + 6) {}
  void update(long long int i, long long int tl, long long int tr,
              long long int ind, long long int val) {
    if (tl == tr) {
      t[i] += val;
      return;
    }
    long long int tmid = (tl + tr) >> 1;
    if (ind <= tmid)
      update(2 * i, tl, tmid, ind, val);
    else
      update(2 * i + 1, tmid + 1, tr, ind, val);
    t[i] = t[2 * i] + t[2 * i + 1];
  }
  void update(long long int ind, long long int val) {
    update(1, 1, n, ind, val);
  }
  long long int query(long long int i, long long int tl, long long int tr,
                      long long int l, long long int r) {
    if (l > r) return 0;
    if (l <= tl && tr <= r) return t[i];
    long long int tmid = (tl + tr) >> 1;
    return query(2 * i, tl, tmid, l, min(r, tmid)) +
           query(2 * i + 1, tmid + 1, tr, max(l, tmid + 1), r);
  }
  long long int query(long long int l, long long int r) {
    return query(1, 1, n, l, r);
  }
};
long long int ans[3000005];
vector<long long int> v[1000005];
vector<long long int> v1[1000005];
vector<long long int> v2[1000005];
long long int start[3000005];
long long int start1[3000005];
long long int end1[3000005];
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  long long int tests = 1;
  for (long long int ii = 0; ii < (long long int)tests; ii++) {
    long long int n, m;
    cin >> n >> m;
    long long int BIG = 1e6;
    long long int cur = 1;
    for (long long int i = 1; i < (long long int)n + 1; i++) {
      long long int l, r;
      cin >> l >> r;
      v[l].push_back(cur);
      v[r].push_back(cur);
      v2[l].push_back(cur);
      v2[r].push_back(cur);
      end1[cur] = r;
      cur++;
    }
    vector<pair<long long int, vector<long long int>>> input;
    for (long long int i = 1; i < (long long int)m + 1; i++) {
      long long int cnt;
      cin >> cnt;
      vector<long long int> vals(cnt);
      for (long long int j = 0; j < (long long int)cnt; j++) cin >> vals[j];
      long long int l = vals[0], r = vals.back();
      v1[l].push_back(cur);
      v1[r].push_back(cur);
      v2[l].push_back(-cur);
      end1[cur] = r;
      cur++;
      long long int temp = cur - 1;
      vector<long long int> temp1;
      long long int prev = vals[0];
      for (long long int j = 1; j < (long long int)cnt; j++) {
        long long int now = vals[j];
        if (prev + 1 <= now - 1) {
          v[prev + 1].push_back(-cur);
          v[now - 1].push_back(-cur);
          temp1.push_back(cur);
          cur++;
        }
        prev = now;
      }
      input.push_back({temp, temp1});
    }
    segtree seg(BIG), seg1(BIG), seg2(BIG);
    for (long long int i = 1; i < (long long int)BIG + 1; i++) {
      sort(v[i].rbegin(), v[i].rend());
      for (auto it : v[i]) {
        if (it < 0) {
          if (!start[-it])
            start[-it] = i;
          else
            ans[-it] = seg.query(start[-it], i);
        } else {
          if (!start[it]) {
            start[it] = i;
            seg1.update(i, 1);
          } else {
            seg.update(start[it], 1);
            seg1.update(start[it], -1);
            seg1.update(i, 1);
          }
        }
      }
      for (auto it : v1[i]) {
        if (!start[it])
          start[it] = i;
        else
          ans[it] = seg1.query(start[it], i);
      }
    }
    for (long long int i = 1; i < (long long int)BIG + 1; i++) {
      sort(v2[i].begin(), v2[i].end());
      for (auto it : v2[i]) {
        if (it < 0) {
          it = -it;
          ans[it] += seg2.query(end1[it] + 1, BIG);
        } else {
          if (!start1[it]) {
            start1[it] = i;
            seg2.update(end1[it], 1);
          } else
            seg2.update(i, -1);
        }
      }
    }
    for (auto& it : input) {
      long long int val1 = it.first;
      vector<long long int>& vals = it.second;
      long long int sol = ans[val1];
      for (long long int x : vals) sol -= ans[x];
      cout << sol << '\n';
    }
  }
  return 0;
}

```