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 gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
int n, m;
vector<pair<int, int> > seg;
vector<int> v;
struct SegmentTreeNode {
  int start, end;
  vector<int> rightseg;
  void assignLeaf(int value) { rightseg.push_back(value); }
  void merge(SegmentTreeNode& left, SegmentTreeNode& right) {
    int a = (int)(left.rightseg.size()), b = (int)(right.rightseg.size());
    int i = 0, j = 0;
    while (i < a && j < b) {
      if (left.rightseg[i] <= right.rightseg[j]) {
        rightseg.push_back(left.rightseg[i]);
        i++;
      } else {
        rightseg.push_back(right.rightseg[j]);
        j++;
      }
    }
    if (i < a) {
      for (int p = i; p < a; p++) rightseg.push_back(left.rightseg[p]);
    } else {
      for (int p = j; p < b; p++) rightseg.push_back(right.rightseg[p]);
    }
  }
  int cal(int l, int r) {
    int index1, index2;
    vector<int>::iterator it1, it2;
    it1 = lower_bound(rightseg.begin(), rightseg.end(), l);
    index1 = it1 - rightseg.begin();
    it2 = lower_bound(rightseg.begin(), rightseg.end(), r);
    it2--;
    index2 = it2 - rightseg.begin();
    return index2 - index1 + 1;
  }
};
SegmentTreeNode nodes[4 * 300010];
class SegmentTree {
 public:
  void build() { buildTree(1, 0, n - 1); }
  int getValue(int lo, int hi, int l, int r) {
    int result = getValue(1, lo, hi, l, r);
    return result;
  }

 private:
  void buildTree(int stIndex, int lo, int hi) {
    nodes[stIndex].start = lo, nodes[stIndex].end = hi;
    if (lo == hi) {
      nodes[stIndex].assignLeaf(seg[lo].second);
      return;
    }
    int left = 2 * stIndex, right = left + 1, mid = (lo + hi) / 2;
    buildTree(left, lo, mid);
    buildTree(right, mid + 1, hi);
    nodes[stIndex].merge(nodes[left], nodes[right]);
  }
  int getValue(int stIndex, int lo, int hi, int l, int r) {
    if (nodes[stIndex].start == lo && nodes[stIndex].end == hi)
      return nodes[stIndex].cal(l, r);
    int mid = (nodes[stIndex].start + nodes[stIndex].end) / 2;
    if (lo > mid) return getValue(2 * stIndex + 1, lo, hi, l, r);
    if (hi <= mid) return getValue(2 * stIndex, lo, hi, l, r);
    int leftResult = getValue(2 * stIndex, lo, mid, l, r);
    int rightResult = getValue(2 * stIndex + 1, mid + 1, hi, l, r);
    int result;
    result = leftResult + rightResult;
    return result;
  }
};
SegmentTree st;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long int ans = 0LL;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    seg.push_back(make_pair(x, y));
  }
  sort(seg.begin(), seg.end());
  st.build();
  for (int i = 0; i < m; i++) {
    v.clear();
    int cnt;
    cin >> cnt;
    ans = 0LL;
    for (int j = 0; j < cnt; j++) {
      int pos;
      cin >> pos;
      v.push_back(pos);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < (int)(v.size()); i++) {
      int val = v[i], nextval, index, temp;
      if (i != (int)(v.size()) - 1)
        nextval = v[i + 1];
      else
        nextval = 1000001;
      vector<pair<int, int> >::iterator it;
      it = upper_bound(seg.begin(), seg.end(), make_pair(val, 1000010));
      it--;
      index = it - seg.begin();
      if (index < 0)
        temp = 0;
      else
        temp = st.getValue(0, index, val, nextval);
      ans += ((long long int)temp);
    }
    cout << ans << "\n";
  }
  return 0;
}