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>
struct pt {
  int x, y;
};
pt *ps;
int *qs = ((int *)malloc((311111) * sizeof(int)));
int xxcomp(pt &a, pt &b) {
  if (a.x != b.x) return a.x - b.x;
  return a.y - b.y;
}
int xcomp(const void *aa, const void *bb) {
  return xxcomp(ps[*(int *)aa], ps[*(int *)bb]);
}
int yycomp(pt &a, pt &b) {
  if (a.y != b.y) return a.y - b.y;
  return a.x - b.x;
}
int ycomp(const void *aa, const void *bb) {
  return yycomp(ps[*(int *)aa], ps[*(int *)bb]);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  ps = ((pt *)malloc((n) * sizeof(pt)));
  int *psx = ((int *)malloc((n) * sizeof(int)));
  int *psy = ((int *)malloc((n) * sizeof(int)));
  for (int i = (0); i < (n); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    ps[i].x = x;
    ps[i].y = y;
    psx[i] = psy[i] = i;
  }
  qsort(psx, n, sizeof(int), xcomp);
  qsort(psy, n, sizeof(int), ycomp);
  int ht = 1;
  for (int sz = 1001111, nsz = sz + 1 >> 1; sz > 1;
       ht++, sz = nsz, nsz = sz + 1 >> 1)
    ;
  int ***arrs = ((int ***)malloc((ht) * sizeof(int **)));
  int **arrc = ((int **)malloc((ht) * sizeof(int *)));
  arrs[0] = ((int **)malloc((1001111) * sizeof(int *)));
  arrc[0] = ((int *)malloc((1001111) * sizeof(int)));
  for (int i = (0); i < (1001111); i++) arrc[0][i] = 0;
  for (int i = (0); i < (n); i++) {
    arrc[0][ps[i].x]++;
  }
  for (int i = (0); i < (1001111); i++) {
    arrs[0][i] = ((int *)malloc((arrc[0][i]) * sizeof(int)));
    arrc[0][i] = 0;
  }
  for (int i = (0); i < (n); i++) {
    int x = ps[i].x;
    arrs[0][x][arrc[0][x]++] = i;
  }
  for (int i = (0); i < (1001111); i++) {
    if (arrc[0][i]) {
      qsort(arrs[0][i], arrc[0][i], sizeof(int), ycomp);
    }
  }
  for (int sz = 1001111, nsz = sz + 1 >> 1, h = 1; sz > 1;
       h++, sz = nsz, nsz = sz + 1 >> 1) {
    arrs[h] = ((int **)malloc((nsz) * sizeof(int *)));
    arrc[h] = ((int *)malloc((nsz) * sizeof(int)));
    for (int i = (0); i < (nsz); i++) {
      int son1 = i << 1;
      int son2 = son1 + 1;
      if (son2 < sz) {
        int *ars1 = arrs[h - 1][son1];
        int *ars2 = arrs[h - 1][son2];
        int arc1 = arrc[h - 1][son1];
        int arc2 = arrc[h - 1][son2];
        arrs[h][i] = ((int *)malloc((arc1 + arc2) * sizeof(int)));
        arrc[h][i] = 0;
        int ison1 = 0, ison2 = 0;
        while (ison1 < arc1 && ison2 < arc2) {
          int comp = yycomp(ps[ars1[ison1]], ps[ars2[ison2]]);
          if (comp <= 0) arrs[h][i][arrc[h][i]++] = ars1[ison1++];
          if (comp >= 0) arrs[h][i][arrc[h][i]++] = ars2[ison2++];
        }
        while (ison1 < arc1) arrs[h][i][arrc[h][i]++] = ars1[ison1++];
        while (ison2 < arc2) arrs[h][i][arrc[h][i]++] = ars2[ison2++];
      } else {
        arrc[h][i] = arrc[h - 1][son1];
        arrs[h][i] = arrs[h - 1][son1];
      }
    }
  }
  while (m--) {
    int c;
    scanf("%d", &c);
    for (int i = (0); i < (c); i++) scanf("%d", qs + i);
    int ans = n;
    int lef = qs[c - 1] + 1, ryg = qs[0] - 1;
    int L, R;
    if (ps[psy[0]].y <= ryg) {
      L = 0, R = n;
      while (R - L > 1) {
        int M = L + R >> 1;
        if (ps[psy[M]].y <= ryg) {
          L = M;
        } else {
          R = M;
        }
      }
      ans -= R;
    }
    if (lef > ps[psx[0]].x) {
      L = 0, R = n;
      while (R - L > 1) {
        int M = L + R >> 1;
        if (lef > ps[psx[M]].x) {
          L = M;
        } else {
          R = M;
        }
      }
      ans -= n - R;
    } else {
      ans -= n;
    }
    for (int ccc = (0); ccc < (c - 1); ccc++) {
      lef = qs[ccc] + 1, ryg = qs[ccc + 1] - 1;
      if (lef > ryg) continue;
      int L = lef, R = 1001111;
      for (int h = 0; L < R; h++, L >>= 1, R >>= 1) {
        if (L & 1) {
          int *ars = arrs[h][L];
          int arc = arrc[h][L];
          if (arc) {
            if (ps[ars[0]].y <= ryg) {
              int l = 0, r = arc;
              while (r - l > 1) {
                int M = l + r >> 1;
                if (ps[ars[M]].y <= ryg) {
                  l = M;
                } else {
                  r = M;
                }
              }
              ans -= r;
            }
          }
          L++;
        }
        if (R & 1) {
          R--;
          int *ars = arrs[h][R];
          int arc = arrc[h][R];
          if (arc) {
            if (ps[ars[0]].y <= ryg) {
              int l = 0, r = arc;
              while (r - l > 1) {
                int M = l + r >> 1;
                if (ps[ars[M]].y <= ryg) {
                  l = M;
                } else {
                  r = M;
                }
              }
              ans -= r;
            }
          }
        }
      }
    }
    printf("%d\n", ans);
  }
}