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 = 6e5 + 2;
const int inf = 1e9;
const int maxSQRT = 1500;
const int SZ = 9;
const int blockSize = 1 << SZ;
const int MOD = blockSize - 1;
struct event {
  int x, type, id, p;
  event() {}
  event(int x, int type, int id) : x(x), type(type), id(id) {}
  void Epr() { fprintf(stderr, "x type id p %d %d %d %d \n", x, type, id, p); }
};
event a[maxn];
int t[maxn];
int b[maxSQRT];
int preCalc[maxSQRT][maxSQRT];
int c[maxn];
int l[maxn];
int r[maxn];
vector<vector<int> > q;
int n, m;
int blockCnt;
inline bool cmp(const event& a, const event& b) {
  return a.x < b.x || (a.x == b.x && a.type > b.type);
}
inline int query(int l, int r) {
  int ll, rr, lb, rb, ans = 0;
  int N = n * 2;
  ll = lower_bound(a, a + N, event(l, 10, 10), cmp) - a;
  rr = lower_bound(a, a + N, event(r, 10, 10), cmp) - a;
  lb = (ll >> SZ) + 1;
  rb = (rr >> SZ);
  int rrr = min(rr, lb * blockSize);
  for (int i = ll; i < rrr; i++) ans += (a[i].type == 1 && a[i].p < rr);
  ans += preCalc[lb][rb];
  if (lb <= rb)
    for (int i = rb * blockSize; i < rr; i++)
      ans += (a[i].type == -1 && a[i].p >= (lb << SZ));
  return ans;
}
void read() {
  int k, x;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &l[i], &r[i]);
  }
  q.resize(m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      scanf("%d", &x);
      q[i].push_back(x);
    }
  }
}
vector<int> solve() {
  int k, res, N;
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    a[i * 2] = event(l[i], 1, i);
    a[i * 2 + 1] = event(r[i], -1, i);
  }
  N = n * 2;
  sort(a, a + N, cmp);
  cerr << "1 time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
  blockCnt = (N + blockSize - 1) / blockSize;
  for (int i = 0; i < N; i++) {
    if (a[i].type == 1) t[a[i].id] = i;
    if (a[i].type == -1) {
      a[i].p = t[a[i].id];
      a[t[a[i].id]].p = i;
    }
  }
  cerr << "2 time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
  for (int i = 0; i < blockCnt; i++) {
    memset(b, 0, sizeof(b));
    for (int j = i * blockSize; j < N; j++)
      b[a[j].p / blockSize] += (a[j].type == 1);
    int cnt = 0;
    for (int j = i; j < blockCnt; j++) {
      cnt += b[j];
      preCalc[i][j + 1] = cnt;
    }
  }
  cerr << "3 time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
  for (int tt = 0; tt < m; tt++) {
    k = q[tt].size();
    c[0] = -100;
    for (int i = 0; i < k; i++) c[i + 1] = q[tt][i];
    c[k + 1] = inf;
    k += 2;
    res = N / 2;
    for (int i = 0; i < k - 1; i++) res -= query(c[i] + 1, c[i + 1]);
    ans.push_back(res);
  }
  cerr << "4 time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
  return ans;
}
void gen() {
  n = 3e5;
  m = 1e5;
  for (int i = 0; i < n; i++) {
    l[i] = rand() % 1000000;
    r[i] = rand() % 1000000;
    if (l[i] > r[i]) swap(l[i], r[i]);
  }
  q.resize(m);
  for (int j = 0; j < m; j++) {
    q[j].clear();
    int k = rand() % 5 + 1;
    for (int i = 0; i < k; i++) q[j].push_back(rand() % 1000000);
    sort(q[j].begin(), q[j].end());
  }
}
vector<int> stupid() {
  vector<pair<int, int> > a;
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    a.push_back(make_pair(l[i], r[i] + 1));
    a.push_back(make_pair(r[i] + 1, l[i]));
  }
  sort(a.begin(), a.end());
  int prev = -1;
  int res = 0;
  int cnt = 0;
  int cur = 0;
  for (int i = 0; i < (int)a.size(); i++) {
    assert(cnt >= 0);
    for (; cur < (int)q[0].size() && q[0][cur] < a[i].first; cur++) {
      prev = q[0][cur];
      res += cnt;
      cnt = 0;
      cerr << "res i: " << res << " " << i << endl;
    }
    if (a[i].first < a[i].second) {
      cnt++;
    } else {
      if (a[i].second > prev) cnt--;
    }
  }
  res += cnt;
  ans.push_back(res);
  return ans;
}
void stress() {
  vector<int> ans1, ans2;
  for (int t = 0; t < 10000; t++) {
    cerr << "test Id: " << t << endl;
    gen();
    ans1 = solve();
    ans2 = stupid();
    assert(ans1.size() == ans2.size());
    bool flag = 1;
    for (int i = 0; i < (int)ans1.size(); i++) flag &= ans1[i] == ans2[i];
    for (int i = 0; i < (int)ans1.size(); i++) cerr << ans1[i] << " ";
    for (int i = 0; i < (int)ans1.size(); i++) cerr << ans2[i] << " ";
    cerr << endl;
    if (!flag) {
      cerr << "fail\n";
      cout << "n m " << n << " " << m << endl;
      for (int i = 0; i < n; i++) cout << l[i] << " " << r[i] << "\n";
      for (int i = 0; i < m; i++, cout << endl)
        for (int j = 0; j < (int)q[i].size(); j++) cout << q[i][j] << " ";
      return;
    }
  }
}
int main() {
  vector<int> ans;
  if (1) {
    if (0)
      stress();
    else {
      read();
      ans = solve();
      for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
    }
    return 0;
  }
  gen();
  cout << n << " " << m << endl;
  for (int i = 0; i < n; i++) cout << l[i] << " " << r[i] << "\n";
  for (int i = 0; i < m; i++, cout << endl) {
    cout << q[i].size() << " ";
    for (int j = 0; j < (int)q[i].size(); j++) cout << q[i][j] << " ";
  }
  return 0;
}