/*
 ***************************************************************************************************************

 Author : Tapan Sahni

 **************************************************************************************************************
 */

#include<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
#include<deque>
#include<map>
#include<set>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<stack>
#include<functional>
using namespace std;
#define LL long long
#define si(x) scanf("%d",&x)
#define sc(x) scanf("%c",&x)
#define sl(x) scanf("%I64d",&x)
#define prl(x) printf("%I64d",x)
#define pri(x) printf("%d\n",x)
#define prs(x) printf("%s\n",x)
typedef pair<int, int> ii;
typedef pair<LL, LL> iil;
typedef pair<LL, iil> iiil;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
#define vl vector<ll>
#define vi vector<int>
#define vii vector<ii>
#define vvl vector< vl >
#define vvi vector< vi >
#define vvii vector< vii >
#define sz size()
#define pb push_back
#define F first
#define S second
#define mem(x,y) memset(x,y,sizeof(x))
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define mod 1000000007
#define pb push_back

const int maxn = 1000000 + 5;
const int INF  = 1e9 + 7;
const int L = 1000000 ;
//const LL INF = 0x0123456789ABCDEFLL;
  struct BIT{
    LL t[maxn + 6];

    void upd(int i, LL v){
        for (; i <= L ; i += i & -i) t[i] += v;
    }

    LL get(int i){
        LL s = 0;
        for (; i; i -= i & -i) s += t[i];
        return s;
    }
};
vector<int> G[maxn + 6];
vector<ii> Q[maxn + 6];
int ans[maxn + 6];
inline void solve(void){
            BIT bit ;
            for(int i = 0; i <= maxn + 5 ;i++) bit.t[i] = 0;
            int n  , m , l ,r , x ,  y;
            cin >> n >> m;
            rep( i , 0 , n){
                cin >> l >> r;
                G[r].pb(l);
            }
            rep(i  , 0 , m){
                    cin >> x;
                    int prev  = 0;
                    rep( j, 0 , x){
                        cin >> y;
                        Q[y - 1].pb(ii(prev +  1 , i));
                        prev = y;
                    }
                    Q[maxn].pb(ii(prev  , i));
            }

           rep(i  , 1 , maxn + 1){
                rep(j , 0 , G[i].sz){
                    bit.upd(G[i][j] , 1);
                }
                  rep(j, 0 , Q[i].sz){
                    ans[Q[i][j].S] += bit.get(i)  - bit.get(Q[i][j].F - 1);

                }
             }
             for(int i = 0 ; i < m ;i++)   cout << n - ans[i] <<endl;

}
void init() {
 ios::sync_with_stdio(false);
 cin.tie(nullptr);
 }
int main(int argc, const char * argv[]){
       init();
    solve();
    return 0;
}


/*
 ***************************************************************************************************************

 Author : Tapan Sahni

 **************************************************************************************************************
 */

#include<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
#include<deque>
#include<map>
#include<set>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<stack>
#include<functional>
using namespace std;
#define LL long long
#define si(x) scanf("%d",&x)
#define sc(x) scanf("%c",&x)
#define sl(x) scanf("%I64d",&x)
#define prl(x) printf("%I64d",x)
#define pri(x) printf("%d\n",x)
#define prs(x) printf("%s\n",x)
typedef pair<int, int> ii;
typedef pair<LL, LL> iil;
typedef pair<LL, iil> iiil;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
#define vl vector<ll>
#define vi vector<int>
#define vii vector<ii>
#define vvl vector< vl >
#define vvi vector< vi >
#define vvii vector< vii >
#define sz size()
#define pb push_back
#define F first
#define S second
#define mem(x,y) memset(x,y,sizeof(x))
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define mod 1000000007
#define pb push_back

const int maxn = 1000000 + 5;
const int INF  = 1e9 + 7;
const int L = 1000000 ;
//const LL INF = 0x0123456789ABCDEFLL;
  struct BIT{
    LL t[maxn + 6];

    void upd(int i, LL v){
        for (; i <= L ; i += i & -i) t[i] += v;
    }

    LL get(int i){
        LL s = 0;
        for (; i; i -= i & -i) s += t[i];
        return s;
    }
};
vector<int> G[maxn + 6];
vector<ii> Q[maxn + 6];
int ans[maxn + 6];
inline void solve(void){
            BIT bit ;
            for(int i = 0; i <= maxn + 5 ;i++) bit.t[i] = 0;
            int n  , m , l ,r , x ,  y;
            cin >> n >> m;
            rep( i , 0 , n){
                cin >> l >> r;
                G[r].pb(l);
            }
            rep(i  , 0 , m){
                    cin >> x;
                    int prev  = 0;
                    rep( j, 0 , x){
                        cin >> y;
                        Q[y - 1].pb(ii(prev +  1 , i));
                        prev = y;
                    }
                    Q[maxn].pb(ii(prev  + 1 , i));
            }

           rep(i  , 1 , maxn + 1){
                rep(j , 0 , G[i].sz){
                    bit.upd(G[i][j] , 1);
                }
                  rep(j, 0 , Q[i].sz){
                    ans[Q[i][j].S] += bit.get(i)  - bit.get(Q[i][j].F - 1);

                }
             }
             for(int i = 0 ; i < m ;i++)   cout << n - ans[i] <<endl;

}
void init() {
 ios::sync_with_stdio(false);
 cin.tie(nullptr);
 }
int main(int argc, const char * argv[]){
       init();
    solve();
    return 0;
}


#include <bits/stdc++.h>
//#include <windows.h>
#define int long long
using namespace std;
int n;
struct TA
{
    int a[10000001];
    inline int lowbit(int a)
    {
        return a&(-a);
    }
    void add(int now,int val)
    {
        for(int i=now; i<=10000000; i+=lowbit(i))
        {
            a[i]+=val;
        }
    }
    int qer(int now)
    {
        if(now==0)
        {
            return 0;
        }
        int ans=0;
        for(int i=now; i>0; i-=lowbit(i))
        {
            ans+=a[i];
        }
        return ans;
    }
} ta;
struct segment
{
    int l,r;
    int id;
    friend bool operator <(segment a,segment b)
    {
        return a.l==b.l?a.id<b.id:a.l>b.l;
    }
} s[1000001];
int top;
int m;
int k;
int lst;
int ans[800001];
signed main()
{
    top=1;
    scanf("%lld%lld",&n,&m);
    for(int i=1; i<=n; i++)
    {
        scanf("%lld%lld",&s[top].l,&s[top].r);
        s[top].id=0;
        top++;
    }
    for(int i=1; i<=m; i++)
    {
        int cnt;
        scanf("%lld",&cnt);
        lst=1;
        while(cnt--)
        {
            scanf("%lld",&k);
            s[top].l=lst;
            s[top].r=k-1;
                s[top].id=i;
                top++;
            lst=k+1;
        }
        s[top].l=lst;
        s[top].r=10000000;
        if(s[top].l<=s[top].r)
        {
            s[top].id=i;
            top++;
        }
    }
    sort(s+1,s+top);
    for(int i=1; i<top; i++)
    {
        if(s[i].id==0)
        {
            //printf("add %d %d\n",s[i].l,s[i].r);
            ta.add(s[i].r,1);
        }
        else
        {
            //printf("qer %d %d %d ans=%d\n",s[i].id,s[i].l,s[i].r,ta.qer(s[i].r));;
            ans[s[i].id]+=ta.qer(s[i].r);
        }
    }
    for(int i=1; i<=m; i++)
    {
        printf("%lld\n",n-ans[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
//#include <windows.h>
#define int long long
using namespace std;
int n;
struct TA
{
    int a[10000001];
    inline int lowbit(int a)
    {
        return a&(-a);
    }
    void add(int now,int val)
    {
        for(int i=now; i<=10000000; i+=lowbit(i))
        {
            a[i]+=val;
        }
    }
    int qer(int now)
    {
        if(now==0)
        {
            return 0;
        }
        int ans=0;
        for(int i=now; i>0; i-=lowbit(i))
        {
            ans+=a[i];
        }
        return ans;
    }
} ta;
struct segment
{
    int l,r;
    int id;
    friend bool operator <(segment a,segment b)
    {
        return a.l==b.l?a.id<b.id:a.l<b.l;
    }
} s[1000001];
int top;
int m;
int k;
int lst;
int ans[800001];
signed main()
{
    top=1;
    scanf("%lld%lld",&n,&m);
    for(int i=1; i<=n; i++)
    {
        scanf("%lld%lld",&s[top].l,&s[top].r);
        s[top].id=0;
        top++;
    }
    for(int i=1; i<=m; i++)
    {
        int cnt;
        scanf("%lld",&cnt);
        lst=1;
        while(cnt--)
        {
            scanf("%lld",&k);
            s[top].l=lst;
            s[top].r=k-1;
                s[top].id=i;
                top++;
            lst=k+1;
        }
        s[top].l=lst;
        s[top].r=10000000;
        if(s[top].l<=s[top].r)
        {
            s[top].id=i;
            top++;
        }
    }
    sort(s+1,s+top);
    for(int i=1; i<top; i++)
    {
        if(s[i].id==0)
        {
            //printf("add %d %d\n",s[i].l,s[i].r);
            ta.add(s[i].r,1);
        }
        else
        {
            //printf("qer %d %d %d ans=%d\n",s[i].id,s[i].l,s[i].r,ta.qer(s[i].r));;
            ans[s[i].id]+=ta.qer(s[i].r);
        }
    }
    for(int i=1; i<=m; i++)
    {
        printf("%lld\n",n-ans[i]);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 3e5 + 5;
const int maxN = 1e6 + 5;
inline ll read()
{
  ll ans = 0;
  char ch = getchar(), last = ' ';
  while(!isdigit(ch)) last = ch, ch = getchar();
  while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
  if(last == '-') ans = -ans;
  return ans;
}
inline void write(ll x)
{
  if(x < 0) x = -x, putchar('-');
  if(x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}

int n, m, Max = 0;
struct Seg
{
  int l, r;
  In bool operator < (const Seg& oth)const
  {
    return l < oth.l || (l == oth.l && r < oth.r);
  }
}t[maxn];

int cnt = 0, tp[maxn], ans[maxn];
struct Node
{
  int L, R, id;
  In bool operator < (const Node& oth)const
  {
    return L < oth.L || (L == oth.L && R < oth.R);
  }
}q[maxn << 1];

int c[maxN];
In int lowbit(int x) {return x & -x;}
In void erase(int pos)
{
  for(; pos < maxn; pos += lowbit(pos)) --c[pos];
}
In void add(int pos)
{
  for(; pos < maxn; pos += lowbit(pos)) ++c[pos];
}
In int query(int pos)
{
  int ret = 0;
  for(; pos; pos -= lowbit(pos)) ret += c[pos];
  return ret;
}

int main()
{
  n = read(); m = read();
  for(int i = 1; i <= n; ++i) t[i].l = read(), t[i].r = read(), Max = max(Max, t[i].r);
  sort(t + 1, t + n + 1);
  for(int i = 1; i <= m; ++i)
    {
      int tot = read();
      for(int j = 1; j <= tot; ++j) tp[j] = read();
      sort(tp + 1, tp + tot + 1);
      for(int j = 1; j <= tot; ++j)
	if(tp[j] != 1 && tp[j - 1] < tp[j] - 1) q[++cnt] = (Node){tp[j - 1] + 1, tp[j] - 1, i};
      //      if(tp[tot] < Max)
	q[++cnt] = (Node){tp[tot] + 1, maxn - 5, i};
    }
  sort(q + 1, q + cnt + 1); q[cnt + 1].L = INF;
  //for(int i = 1; i <= cnt; ++i) printf("!%d %d %d\n", q[i].L, q[i].R, q[i].id);
  for(int i = 1, j = 1, k = 1; i <= cnt; ++i)
    {
      while(t[k].l < q[i].L && k <= m) erase(t[k++].r);
      if(k > j) j = k;
      while(t[j].l <= q[i].R && j <= m) add(t[j++].r);
      int tp = query(q[i].R);
      //printf("%d %d %d %d\n", i, k, j, tp);
      ans[q[i].id] += tp;
    }
  for(int i = 1; i <= m; ++i) write(n - ans[i]), enter;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5+5;
#define lowbit(i) (i&(-i))
int readint(){
    int x=0,f=1;char s=getchar();
    #define sc (s=getchar())
    while(s<'0'||s>'9'){
        if(s=='-')
            f=-1;
        sc;
    }
    while(s>='0'&&s<='9'){
        x=(x<<3)+(x<<1)+(s^48);
        sc;
    }
    #undef sc
    return x*f;
}
int bit[maxn];
void add(int x,int val){
    for(int i=x;i<=maxn-5;i+=lowbit(i)){
        bit[i]+=val;
    }
}
int sum(int x){
    int ans=0;
    for(int i=x;i;i-=lowbit(i))
        ans+=bit[i];
    return ans;
}
struct zz{
    int l,r,ind;
    zz(){};
    zz(int L,int R,int I){
        l=L;
        r=R;
        ind=I;
    }
    bool operator <(const zz &com)const{
        if(l!=com.l)
            return l>com.l;
        if(r!=com.r)
            return r<com.r;
        return ind<com.ind;
    }
}s[maxn<<2];
int a[maxn];
bool cmp(const zz &x,const zz &y){
    if(x.l!=y.l)
        return x.l>y.l;
    if(x.r!=y.r)
        return x.r<y.r;
    return x.ind<y.ind;
}
int ans[maxn];
int main (){
    int n=readint(),m=readint();
    int cnt=n;
    for(int i=1;i<=n;i++){
        s[i].l=readint(),s[i].r=readint();
    }
    for(int times=1;times<=m;times++){
        int k=readint();
        for(int i=1;i<=k;i++){
            a[i]=readint();
            s[++cnt]=zz(a[i-1]+1,a[i]-1,times);
        }
        s[++cnt]=zz(a[k]+1,maxn-5,times);
    }
    sort(s+1,s+cnt+1);
    for(int i=1;i<=cnt;i++){
        if(s[i].ind)
            ans[s[i].ind]+=sum(s[i].r);
        else
            add(s[i].r,1);
    }
    for(int i=1;i<=m;i++){
        printf("%d\n",n-ans[i]);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MAXN 300005
#define MAXM 1000005
#define lowbit(x) (x&-x)
typedef long long LL;
typedef pair<LL,LL> pii;
int n,m,tot,t[MAXN],val[MAXM<<2],ans[MAXN];
vector<int> G[MAXM];
struct ming{
	int l,r,id;
	bool friend operator < (const ming &x,const ming &y){
		if(x.l==y.l)return x.r>y.r;
		return x.l>y.l;
	}
}qj[MAXN<<1],line[MAXN];
void insert(int rt,int l,int r,int ai,int aw){
	//printf("%d %d %d\n",l,r,ai);
	if(l>r||l>ai||r<ai)return ;
	if(l==r){val[rt]+=aw;return ;}
	int mid=l+r>>1;
	if(ai<=mid)insert(rt<<1,l,mid,ai,aw);
	else insert(rt<<1|1,mid+1,r,ai,aw);
	val[rt]=val[rt<<1]+val[rt<<1|1];
}
int query(int rt,int l,int r,int al,int ar){
	if(l>r||l>ar||r<al)return 0;
	if(al<=l&&r<=ar)return val[rt];
	int mid=l+r>>1,sum=0;
	if(al<=mid)sum+=query(rt<<1,l,mid,al,ar);
	if(ar>mid)sum+=query(rt<<1|1,mid+1,r,al,ar);
	return sum;
}
void search(int rt,int l,int r){
	//printf("%d %d:%d\n",l,r,val[rt]);
	if(l==r)return ;
	int mid=l+r>>1;
	search(rt<<1,l,mid);
	search(rt<<1|1,mid+1,r);
}
signed main(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++){
		int l,r;scanf("%d %d",&l,&r);
		line[i]=(ming){l,r,0};
	}
	for(int i=1;i<=m;i++){
		int cnt;scanf("%d",&cnt);
		for(int j=1;j<=cnt;j++)
			scanf("%d",&t[j]);
		if(t[1]>1)qj[++tot]=(ming){1,t[1]-1,i};
		if(t[cnt]<1000000)qj[++tot]=(ming){t[cnt]+1,1000000,i};
		for(int j=2;j<=cnt;j++)
			if(t[j-1]+1<t[j])
				qj[++tot]=(ming){t[j-1]+1,t[j]-1,i};
	}
	sort(qj+1,qj+tot+1);qj[0].l=1000001;
	sort(line+1,line+n+1);int id=1;
	for(int i=1;i<=tot;i++){
		if(qj[i].l<qj[i-1].l)
			while(line[id].l>=qj[i].l&&id<=n){
				//printf("%d %d\n",line[id].l,line[id].r);
				insert(1,1,1000000,line[id].r,1),id++;
			}
		ans[qj[i].id]+=query(1,1,1000000,1,qj[i].r);
		search(1,1,n);
		//printf("%d %d %d:%d\n",qj[i].l,qj[i].r,qj[i].id,ans[qj[i].id]);
	}
	for(int i=1;i<=m;i++)printf("%d\n",n-ans[i]);
	return 0;
}


/*Code by 520 -- 10.5*/
#include<bits/stdc++.h>
#define il inline
#define ll long long
#define RE register
#define For(i,a,b) for(RE int (i)=(a);(i)<=(b);(i)++)
#define Bor(i,a,b) for(RE int (i)=(b);(i)>=(a);(i)--)
#define lowbit(x) (x&-x)
using namespace std;
const int N=3e5+5,M=1e6+5;
int n,m,c[M],ans[N];
struct node{
	int l,r,id;
	bool operator < (const node &a) const {return l==a.l?(r==a.r?id<a.id:r<a.r):l>a.l;}
}t[N];

int gi(){
	int a=0;char x=getchar();
	while(x<'0'||x>'9') x=getchar();
	while(x>='0'&&x<='9') a=(a<<3)+(a<<1)+(x^48),x=getchar();
	return a;
}

il void update(int x,int v){while(x<M)c[x]+=v,x+=lowbit(x);}

il int query(int x){int res=0;while(x)res+=c[x],x-=lowbit(x);return res;}

int main(){
	n=gi(),m=gi();
	For(i,1,n) t[i]=node{gi(),gi(),0};
	int tot=n,k,tp,lst;
	For(i,1,m){
		k=gi(),tp=gi();
		if(tp>1) t[++tot]=node{1,tp-1,i};
		lst=tp;
		For(j,2,k){
			tp=gi();
			if(tp-1>=lst+1) t[++tot]=node{lst+1,tp-1,i};
			lst=tp;
		}
		t[++tot]=node{lst+1,1000000,i};
	}
	sort(t+1,t+tot+1);
	For(i,1,tot)
		if(!t[i].id) update(t[i].r,1);
		else ans[t[i].id]+=query(t[i].r);
	For(i,1,m) printf("%d\n",n-ans[i]);
	return 0;
}


#include <bits/stdc++.h>
//#include <windows.h>
#define int long long
using namespace std;
int n;
struct TA
{
    int a[5000001];
    inline int lowbit(int a)
    {
        return a&(-a);
    }
    void add(int now,int val)
    {
        for(int i=now; i<=5000000; i+=lowbit(i))
        {
            a[i]+=val;
        }
    }
    int qer(int now)
    {
        if(now==0)
        {
            return 0;
        }
        int ans=0;
        for(int i=now; i>0; i-=lowbit(i))
        {
            ans+=a[i];
        }
        return ans;
    }
    int ask(int l,int r)
    {
        return qer(r)-qer(l-1);
    }
} ta;
struct segment
{
    int l,r;
    int id;
    friend bool operator <(segment a,segment b)
    {
        return a.l>b.l;
    }
} s[800001];
int top;
int m;
int k;
int lst;
int ans[400001];
signed main()
{
    top=1;
    scanf("%lld%lld",&n,&m);
    for(int i=1; i<=n; i++)
    {
        scanf("%lld%lld",&s[top].l,&s[top].r);
        s[top].id=0;
        top++;
    }
    for(int i=1; i<=m; i++)
    {
        int cnt;
        scanf("%lld",&cnt);
        lst=1;
        while(cnt--)
        {
            scanf("%lld",&k);
            s[top].l=lst;
            s[top].r=k-1;
            if(s[top].l<=s[top].r)
            {
                s[top].id=i;
                top++;
            }
            lst=k+1;
        }
        s[top].l=lst;
        s[top].r=5000000;
        if(s[top].l<=s[top].r)
        {
            s[top].id=i;
            top++;
        }
    }
    sort(s+1,s+top);
    for(int i=1; i<top; i++)
    {
        if(s[i].id==0)
        {
            //printf("add %d %d\n",s[i].l,s[i].r);
            ta.add(s[i].r,1);
        }
        else
        {
            //printf("qer %d %d %d ans=%d\n",s[i].id,s[i].l,s[i].r,ta.qer(s[i].r));;
            ans[s[i].id]+=ta.qer(s[i].r);
        }
    }
    for(int i=1; i<=m; i++)
    {
        printf("%lld\n",n-ans[i]);
    }
    return 0;
}


/*Code by 520 -- 10.5*/
#include<bits/stdc++.h>
#define il inline
#define ll long long
#define RE register
#define For(i,a,b) for(RE int (i)=(a);(i)<=(b);(i)++)
#define Bor(i,a,b) for(RE int (i)=(b);(i)>=(a);(i)--)
#define lowbit(x) (x&-x)
using namespace std;
const int N=3e5+5,M=1e6+5;
int n,m,c[M],ans[N];
struct node{
	int l,r,id;
	bool operator < (const node &a) const {return l==a.l?(r==a.r?id<a.id:r<a.r):l>a.l;}
}t[N];

int gi(){
	int a=0;char x=getchar();
	while(x<'0'||x>'9') x=getchar();
	while(x>='0'&&x<='9') a=(a<<3)+(a<<1)+(x^48),x=getchar();
	return a;
}

il void update(int x,int v){while(x<M)c[x]+=v,x+=lowbit(x);}

il int query(int x){int res=0;while(x)res+=c[x],x-=lowbit(x);return res;}

int main(){
	while(scanf("%d%d",&n,&m)!=EOF){
	    For(i,1,n) t[i]=node{gi(),gi(),0};
	    int tot=n,k,tp,lst;
	    For(i,1,m){
		    k=gi(),tp=gi();
		    if(tp>1) t[++tot]=node{1,tp-1,i};
		    lst=tp;
		    For(j,2,k){
			    tp=gi();
			    if(tp-1>=lst+1) t[++tot]=node{lst+1,tp-1,i};
			    lst=tp;
		    }
		    t[++tot]=node{lst+1,1000000,i};
	    }
	    sort(t+1,t+tot+1);
	    For(i,1,tot)
		    if(!t[i].id) update(t[i].r,1);
		    else ans[t[i].id]+=query(t[i].r);
	    For(i,1,m) printf("%d\n",n-ans[i]);
	    memset(ans,0,sizeof(ans)),memset(c,0,sizeof(c));
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
struct node {
	int ind,l,r;
	node(){};
	node(int I,int L,int R){
		ind = I,l = L,r = R;
	}
	bool operator < (const node &rhs)const {
		if (l != rhs.l)
			return l > rhs.l;
		else if (r == rhs.r)
			return r < rhs.r;
		else
			return ind < rhs.ind;
	}
}s[2000005];
int n,m,tot,c[1000005],ans[1000005];
int lowbit(int x){
	return x & (-x);
}
void add(int x){
	for (;x <= 1e6;x += lowbit(x))
		c[x] ++;
}
int sum(int x){
	int res = 0;
	for (;x >= 1;x -= lowbit(x))
		res += c[x];
	return res;
}
int main(){
	scanf ("%d%d",&n,&m);
	for (int i = 1;i <= n;i ++){
		scanf ("%d%d",&s[i].l,&s[i].r);
		s[i].ind = 0;
	}
	tot = n;
	for (int i = 1;i <= m;i ++){
		int cnt;
		scanf ("%d",&cnt);
		ans[i] = n;
		int last = 0;
		for (int j = 1;j <= cnt;j ++){
			int a;
			scanf ("%d",&a);
			if (a > 1 && last < a - 1)
				s[++ tot] = node(i,last + 1,a - 1);
			last = a;
		}
		s[++ tot] = node(i,last + 1,1e6 + 5);
	}
	sort(s + 1,s + 1 + tot);
	for (int i = 1;i <= tot;i ++){
		if (s[i].ind)
			ans [s[i].ind] -= sum(s[i].r);
		else
			add(s[i].r);
	}
	for (int i = 1;i <= m;i ++){
		printf("%d\n",ans[i]);
	}
}


#include <bits/stdc++.h>
using namespace std;

const int maxn=2e6;
int n,m;
struct node
{
    int l,r,pos;
    bool operator <(const node &b)const
    {
        if(l==b.l){
            if(pos==b.pos)return pos<b.pos;
            return r<b.r;
        }
        return l>b.l;
    }
}a[maxn+7];
int ans[maxn+7],c[maxn+7];
int lowbit(int x)
{
    return x&-x;
}
void add(int x,int val)
{
    while(x<=maxn){
        c[x]+=val;
        x+=lowbit(x);
    }
}
int sum(int x)
{
    int res=0;
    while(x>0){
        res+=c[x];
        x-=lowbit(x);
    }
    return res;
}
int main()
{
    int cnt=0;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        int l,r;
        scanf("%d%d",&l,&r);
        ++cnt;
        a[cnt].l=l;a[cnt].r=r;a[cnt].pos=0;
    }
    for(int i=1;i<=m;i++){
        int op;
        scanf("%d",&op);
        int x;
        scanf("%d",&x);
        if(x>1){
            ++cnt;
            a[cnt].l=1;a[cnt].r=x;a[cnt].pos=i;
        }
        int pre=x;
        for(int j=2;j<=op;j++){
            scanf("%d",&x);
            if(x>=pre+1){
                ++cnt;
                a[cnt].l=pre+1;a[cnt].r=x;a[cnt].pos=i;
            }
            pre=x;
        }
        ++cnt;
        a[cnt].l=pre+1,a[cnt].r=maxn;a[cnt].pos=i;
    }
    sort(a+1,a+1+cnt);
    for(int i=1;i<=cnt;i++){
        if(a[i].pos==0){
            add(a[i].r,1);
        }
        else{
            ans[a[i].pos]+=sum(a[i].r-1);
        }
    }
    for(int i=1;i<=m;i++){
        printf("%d\n",n-ans[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn=2e6;
int n,m;
struct node
{
    int l,r,pos;
    bool operator <(const node &b)const
    {
        if(l==b.l){
            if(pos==b.pos)return pos<b.pos;
            return r<b.r;
        }
        return l>b.l;
    }
}a[maxn+7];
int ans[maxn+7],c[maxn+7];
int lowbit(int x)
{
    return x&-x;
}
void add(int x,int val)
{
    while(x<=maxn){
        c[x]+=val;
        x+=lowbit(x);
    }
}
int sum(int x)
{
    int res=0;
    while(x>0){
        res+=c[x];
        x-=lowbit(x);
    }
    return res;
}
int main()
{
    int cnt=0;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        int l,r;
        scanf("%d%d",&l,&r);
        ++cnt;
        a[cnt].l=l;a[cnt].r=r;a[cnt].pos=0;
    }
    for(int i=1;i<=m;i++){
        int op;
        scanf("%d",&op);
        int x;
        scanf("%d",&x);
        if(x>1){
            ++cnt;
            a[cnt].l=1;a[cnt].r=x-1;a[cnt].pos=i;
        }
        int pre=x;
        for(int j=2;j<=op;j++){
            scanf("%d",&x);
            if(x-1>=pre+1){
                ++cnt;
                a[cnt].l=pre+1;a[cnt].r=x-1;a[cnt].pos=i;
            }
            pre=x;
        }
        ++cnt;
        a[cnt].l=pre+1,a[cnt].r=maxn;a[cnt].pos=i;
    }
    sort(a+1,a+1+cnt);
    for(int i=1;i<=cnt;i++){
        if(a[i].pos==0){
            add(a[i].r,1);
        }
        else{
            ans[a[i].pos]+=sum(a[i].r);
        }
    }
    for(int i=1;i<=m;i++){
        printf("%d\n",n-ans[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn=2e6;
int n,m;
struct node
{
    int l,r,pos;
    bool operator <(const node &b)const
    {
        if(l==b.l){
            if(pos==b.pos)return pos<b.pos;
            return r<b.r;
        }
        return l>b.l;
    }
}a[maxn+7];
int ans[maxn+7],c[maxn+7];
int lowbit(int x)
{
    return x&-x;
}
void add(int x,int val)
{
    while(x<=maxn){
        c[x]+=val;
        x+=lowbit(x);
    }
}
int sum(int x)
{
    int res=0;
    while(x>0){
        res+=c[x];
        x-=lowbit(x);
    }
    return res;
}
int main()
{
    int cnt=0;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        int l,r;
        scanf("%d%d",&l,&r);
        ++cnt;
        a[cnt].l=l;a[cnt].r=r;a[cnt].pos=0;
    }
    for(int i=1;i<=m;i++){
        int op;
        scanf("%d",&op);
        int x;
        scanf("%d",&x);
        if(x>1){
            ++cnt;
            a[cnt].l=1;a[cnt].r=x;a[cnt].pos=i;
        }
        int pre=x;
        for(int j=2;j<=op;j++){
            scanf("%d",&x);
            if(x-1>=pre+1){
                ++cnt;
                a[cnt].l=pre+1;a[cnt].r=x;a[cnt].pos=i;
            }
            pre=x;
        }
        ++cnt;
        a[cnt].l=pre+1,a[cnt].r=maxn;a[cnt].pos=i;
    }
    sort(a+1,a+1+cnt);
    for(int i=1;i<=cnt;i++){
        if(a[i].pos==0){
            add(a[i].r,1);
        }
        else{
            ans[a[i].pos]+=sum(a[i].r-1);
        }
    }
    for(int i=1;i<=m;i++){
        printf("%d\n",n-ans[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int maxn=2e6;
int n,m;
struct node
{
    int l,r,pos;
    bool operator <(const node &b)const
    {
        if(l==b.l){
            if(r==b.r)return pos<b.pos;
            return r<b.r;
        }
        return l>b.l;
    }
}a[maxn+7];
int ans[maxn+7],c[maxn+7];
int lowbit(int x)
{
    return x&-x;
}
void add(int x,int val)
{
    while(x<=maxn){
        c[x]+=val;
        x+=lowbit(x);
    }
}
int sum(int x)
{
    int res=0;
    while(x>0){
        res+=c[x];
        x-=lowbit(x);
    }
    return res;
}
int main()
{
    int cnt=0;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        int l,r;
        scanf("%d%d",&l,&r);
        ++cnt;
        a[cnt].l=l;a[cnt].r=r;a[cnt].pos=0;
    }
    for(int i=1;i<=m;i++){
        int op;
        scanf("%d",&op);
        int x;
        scanf("%d",&x);
        if(x>1){
            ++cnt;
            a[cnt].l=1;a[cnt].r=x;a[cnt].pos=i;
        }
        int pre=x;
        for(int j=2;j<=op;j++){
            scanf("%d",&x);
            if(x>=pre+1){
                ++cnt;
                a[cnt].l=pre+1;a[cnt].r=x;a[cnt].pos=i;
            }
            pre=x;
        }
        ++cnt;
        a[cnt].l=pre+1,a[cnt].r=maxn;a[cnt].pos=i;
    }
    sort(a+1,a+1+cnt);
    for(int i=1;i<=cnt;i++){
        if(a[i].pos==0){
            add(a[i].r,1);
        }
        else{
            ans[a[i].pos]+=sum(a[i].r-1);
        }
    }
    for(int i=1;i<=m;i++){
        printf("%d\n",n-ans[i]);
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cstdlib>
#include <string>
#include <complex>
#include <bitset>
#include <cmath>
#include <stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<pii, int> piii;
typedef pair<pll, ll> plll;
typedef pair<pdd, double> pddd;
typedef complex<double> cpx;
#define mst(x,v) memset(x,v,sizeof(x))
#define rgs register
#define rp(k,x,v) for(rgs int k = x;k<v;++k)
#define rps(s) for(rgs int i = 0;s[i];++i)
#define RP(k,x,v) for(rgs int k = x;k<=v;++k)
#define lp(k,x,v) for(rgs int k = x;k>v;--k)
#define LP(k,x,v) for(rgs int k = x;k>=v;--k)
#define lowbit(x) (x&-x)
#define adde(u,v) edg[++ecnt]=Edge(u,v,g[u]),g[u]=ecnt
#define addew(u,v,w) edg[++ecnt]=Edge(u,v,g[u],w),g[u]=ecnt
#define addedg(u,v,w,cap) edg[++ecnt]=Edge(u,v,g[u],w,cap),g[u]=ecnt,edg[++ecnt]=Edge(v,u,g[v],-w,0),g[v]=ecnt
#define fson(x) for(rgs int i = g[x];~i;i=edg[i].next)
#define LB lower_bound
#define UB upper_bound
#define inp(n,a) RP(i,1,n) ru(a[i]);
#define mpt int mid = l+r>>1;
#define all(a) a.begin(),a.end()
#define inr (ql<=l && r<=qr)
#define upmax(a,b) a=max(a,b)
#define upmin(a,b) a=min(a,b)
const int INF = 1 << 29;
const ll LINF = 1LL << 60;
const double inf = 1e15;
ll mod = 1e9 + 7;
char READ_DATA;
int SIGNAL_INPUT;
template <typename Type>
inline Type ru(Type &v)
{
	SIGNAL_INPUT = 1;
	while ((READ_DATA = getchar()) < '0' || READ_DATA > '9')
		if (READ_DATA == '-')
			SIGNAL_INPUT = -1;
		else if (READ_DATA == EOF)
			return EOF;
	v = READ_DATA - '0';
	while ((READ_DATA = getchar()) >= '0' && READ_DATA <= '9')
		v = v * 10 + READ_DATA - '0';
	v *= SIGNAL_INPUT;
	return v;
}
inline ll modru(ll &v)
{
	ll p = 0;
	SIGNAL_INPUT = 1;
	while ((READ_DATA = getchar()) < '0' || READ_DATA > '9')
		if (READ_DATA == '-')
			SIGNAL_INPUT = -1;
		else if (READ_DATA == EOF)
			return EOF;
	p = v = READ_DATA - '0';
	while ((READ_DATA = getchar()) >= '0' && READ_DATA <= '9')
	{
		v = (v * 10 + READ_DATA - '0') % mod;
		p = (p * 10 + READ_DATA - '0') % (mod - 1);
	}
	v *= SIGNAL_INPUT;
	return p;
}
template<typename A, typename B > inline char ru(A&x, B&y) { if (ru(x) == EOF) return EOF; ru(y); return 2; }
template<typename A, typename B, typename C>inline char ru(A&x, B&y, C&z) { if (ru(x) == EOF) return EOF; ru(y); ru(z); return 3; }
template<typename A, typename B, typename C, typename D>inline char ru(A&x, B&y, C&z, D&w) { if (ru(x) == EOF) return EOF; ru(y); ru(z); ru(w); return 4; }

struct Edge
{
	int  u, v, next;
	ll w, cap, flow;
	Edge(int _u = 0, int _v = 0, int nxt = -1, ll _w = 1, ll _cap = 0)
	{
		u = _u;
		v = _v;
		w = _w;
		cap = _cap;
		flow = 0;
		next = nxt;
	}

	int operator<(const Edge &b) const
	{
		return w < b.w;
	}
};

const int maxn = 3e5 + 2, N = 2e6 + 1;
double eps = 1e-7, pi = acos(-1.0);
ull seed = 131, smod = (1LL << 32) - 267;

struct BIT
{
	int t[maxn*10], n;

	void add(int x, int d)
	{
		while (x <= n)
		{
			t[x] += d;
			x += lowbit(x);
		}
	}

	int sum(int x)
	{
		int ans = 0;
		while (x)
		{
			ans += t[x];
			x -= lowbit(x);
		}
		return ans;
	}
	int sum(int l, int r)
	{
		return sum(r) - sum(l - 1);
	}
}bit;

struct Seg
{
	int l, r, id;
	int operator<(const Seg &cmp) const
	{
		return r < cmp.r;
	}
}a[maxn << 2];
int cnt;

int n, m, ans[maxn];

int main()
{
	bit.n = 1e6;
	ru(n, m);
	RP(i, 1, n)
	{
		++cnt;
		ru(a[cnt].l, a[cnt].r);
		a[cnt].id = 0;
	}
	int t, last, x;
	RP(i, 1, m)
	{
		last = 0;
		ru(t);
		while (t--)
		{
			++cnt;
			ru(x);
			a[cnt].l = last + 1; a[cnt].r = x - 1; a[cnt].id = i;
			last = x;
		}
		++cnt;
		a[cnt].l = last + 1; a[cnt].r = 1e6; a[cnt].id = i;
	}
	sort(a + 1, a + cnt + 1);
	RP(i, 1, cnt)
	{
		if (a[i].id)
		{
			if (a[i].l <= a[i].r)
				ans[a[i].id] += bit.sum(a[i].l, 1e6);
		}
		else
			bit.add(a[i].l, 1);
	}
	RP(i, 1, m) printf("%d\n", n-ans[i]);
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cstdlib>
#include <string>
#include <complex>
#include <bitset>
#include <cmath>
#include <stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<pii, int> piii;
typedef pair<pll, ll> plll;
typedef pair<pdd, double> pddd;
typedef complex<double> cpx;
#define mst(x,v) memset(x,v,sizeof(x))
#define rgs register
#define rp(k,x,v) for(rgs int k = x;k<v;++k)
#define rps(s) for(rgs int i = 0;s[i];++i)
#define RP(k,x,v) for(rgs int k = x;k<=v;++k)
#define lp(k,x,v) for(rgs int k = x;k>v;--k)
#define LP(k,x,v) for(rgs int k = x;k>=v;--k)
#define lowbit(x) (x&-x)
#define adde(u,v) edg[++ecnt]=Edge(u,v,g[u]),g[u]=ecnt
#define addew(u,v,w) edg[++ecnt]=Edge(u,v,g[u],w),g[u]=ecnt
#define addedg(u,v,w,cap) edg[++ecnt]=Edge(u,v,g[u],w,cap),g[u]=ecnt,edg[++ecnt]=Edge(v,u,g[v],-w,0),g[v]=ecnt
#define fson(x) for(rgs int i = g[x];~i;i=edg[i].next)
#define LB lower_bound
#define UB upper_bound
#define inp(n,a) RP(i,1,n) ru(a[i]);
#define mpt int mid = l+r>>1;
#define all(a) a.begin(),a.end()
#define inr (ql<=l && r<=qr)
#define upmax(a,b) a=max(a,b)
#define upmin(a,b) a=min(a,b)
const int INF = 1 << 29;
const ll LINF = 1LL << 60;
const double inf = 1e15;
ll mod = 1e9 + 7;
char READ_DATA;
int SIGNAL_INPUT;
template <typename Type>
inline Type ru(Type &v)
{
	SIGNAL_INPUT = 1;
	while ((READ_DATA = getchar()) < '0' || READ_DATA > '9')
		if (READ_DATA == '-')
			SIGNAL_INPUT = -1;
		else if (READ_DATA == EOF)
			return EOF;
	v = READ_DATA - '0';
	while ((READ_DATA = getchar()) >= '0' && READ_DATA <= '9')
		v = v * 10 + READ_DATA - '0';
	v *= SIGNAL_INPUT;
	return v;
}
inline ll modru(ll &v)
{
	ll p = 0;
	SIGNAL_INPUT = 1;
	while ((READ_DATA = getchar()) < '0' || READ_DATA > '9')
		if (READ_DATA == '-')
			SIGNAL_INPUT = -1;
		else if (READ_DATA == EOF)
			return EOF;
	p = v = READ_DATA - '0';
	while ((READ_DATA = getchar()) >= '0' && READ_DATA <= '9')
	{
		v = (v * 10 + READ_DATA - '0') % mod;
		p = (p * 10 + READ_DATA - '0') % (mod - 1);
	}
	v *= SIGNAL_INPUT;
	return p;
}
template<typename A, typename B > inline char ru(A&x, B&y) { if (ru(x) == EOF) return EOF; ru(y); return 2; }
template<typename A, typename B, typename C>inline char ru(A&x, B&y, C&z) { if (ru(x) == EOF) return EOF; ru(y); ru(z); return 3; }
template<typename A, typename B, typename C, typename D>inline char ru(A&x, B&y, C&z, D&w) { if (ru(x) == EOF) return EOF; ru(y); ru(z); ru(w); return 4; }

struct Edge
{
	int  u, v, next;
	ll w, cap, flow;
	Edge(int _u = 0, int _v = 0, int nxt = -1, ll _w = 1, ll _cap = 0)
	{
		u = _u;
		v = _v;
		w = _w;
		cap = _cap;
		flow = 0;
		next = nxt;
	}

	int operator<(const Edge &b) const
	{
		return w < b.w;
	}
};

const int maxn = 3e5 + 2, N = 2e6 + 1;
double eps = 1e-7, pi = acos(-1.0);
ull seed = 131, smod = (1LL << 32) - 267;

struct BIT
{
	int t[maxn*10], n;

	void add(int x, int d)
	{
		while (x <= n)
		{
			t[x] += d;
			x += lowbit(x);
		}
	}

	int sum(int x)
	{
		int ans = 0;
		while (x)
		{
			ans += t[x];
			x -= lowbit(x);
		}
		return ans;
	}
	int sum(int l, int r)
	{
		return sum(r) - sum(l - 1);
	}
}bit;

struct Seg
{
	int l, r, id;
	int operator<(const Seg &cmp) const
	{
		return r < cmp.r;
	}
}a[maxn * 10];
int cnt;

int n, m, ans[maxn];

int main()
{
	bit.n = 1e6;
	ru(n, m);
	RP(i, 1, n)
	{
		++cnt;
		ru(a[cnt].l, a[cnt].r);
		a[cnt].id = 0;
	}
	int t, last, x;
	RP(i, 1, m)
	{
		last = 0;
		ru(t);
		while (t--)
		{
			++cnt;
			ru(x);
			a[cnt].l = last + 1; a[cnt].r = x - 1; a[cnt].id = i;
			last = x;
		}
		++cnt;
		a[cnt].l = last + 1; a[cnt].r = 1e6; a[cnt].id = i;
	}
	sort(a + 1, a + cnt + 1);
	RP(i, 1, cnt)
	{
		if (a[i].id)
		{
			if (a[i].l <= a[i].r)
				ans[a[i].id] += bit.sum(a[i].l, 1e6);
		}
		else
			bit.add(a[i].l, 1);
	}
	RP(i, 1, m) printf("%d\n", n-ans[i]);
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cstdlib>
#include <string>
#include <complex>
#include <bitset>
#include <cmath>
#include <stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<pii, int> piii;
typedef pair<pll, ll> plll;
typedef pair<pdd, double> pddd;
typedef complex<double> cpx;
#define mst(x,v) memset(x,v,sizeof(x))
#define rgs register
#define rp(k,x,v) for(rgs int k = x;k<v;++k)
#define rps(s) for(rgs int i = 0;s[i];++i)
#define RP(k,x,v) for(rgs int k = x;k<=v;++k)
#define lp(k,x,v) for(rgs int k = x;k>v;--k)
#define LP(k,x,v) for(rgs int k = x;k>=v;--k)
#define lowbit(x) (x&-x)
#define adde(u,v) edg[++ecnt]=Edge(u,v,g[u]),g[u]=ecnt
#define addew(u,v,w) edg[++ecnt]=Edge(u,v,g[u],w),g[u]=ecnt
#define addedg(u,v,w,cap) edg[++ecnt]=Edge(u,v,g[u],w,cap),g[u]=ecnt,edg[++ecnt]=Edge(v,u,g[v],-w,0),g[v]=ecnt
#define fson(x) for(rgs int i = g[x];~i;i=edg[i].next)
#define LB lower_bound
#define UB upper_bound
#define inp(n,a) RP(i,1,n) ru(a[i]);
#define mpt int mid = l+r>>1;
#define all(a) a.begin(),a.end()
#define inr (ql<=l && r<=qr)
#define upmax(a,b) a=max(a,b)
#define upmin(a,b) a=min(a,b)
const int INF = 1 << 29;
const ll LINF = 1LL << 60;
const double inf = 1e15;
ll mod = 1e9 + 7;
char READ_DATA;
int SIGNAL_INPUT;
template <typename Type>
inline Type ru(Type &v)
{
	SIGNAL_INPUT = 1;
	while ((READ_DATA = getchar()) < '0' || READ_DATA > '9')
		if (READ_DATA == '-')
			SIGNAL_INPUT = -1;
		else if (READ_DATA == EOF)
			return EOF;
	v = READ_DATA - '0';
	while ((READ_DATA = getchar()) >= '0' && READ_DATA <= '9')
		v = v * 10 + READ_DATA - '0';
	v *= SIGNAL_INPUT;
	return v;
}
inline ll modru(ll &v)
{
	ll p = 0;
	SIGNAL_INPUT = 1;
	while ((READ_DATA = getchar()) < '0' || READ_DATA > '9')
		if (READ_DATA == '-')
			SIGNAL_INPUT = -1;
		else if (READ_DATA == EOF)
			return EOF;
	p = v = READ_DATA - '0';
	while ((READ_DATA = getchar()) >= '0' && READ_DATA <= '9')
	{
		v = (v * 10 + READ_DATA - '0') % mod;
		p = (p * 10 + READ_DATA - '0') % (mod - 1);
	}
	v *= SIGNAL_INPUT;
	return p;
}
template<typename A, typename B > inline char ru(A&x, B&y) { if (ru(x) == EOF) return EOF; ru(y); return 2; }
template<typename A, typename B, typename C>inline char ru(A&x, B&y, C&z) { if (ru(x) == EOF) return EOF; ru(y); ru(z); return 3; }
template<typename A, typename B, typename C, typename D>inline char ru(A&x, B&y, C&z, D&w) { if (ru(x) == EOF) return EOF; ru(y); ru(z); ru(w); return 4; }

struct Edge
{
	int  u, v, next;
	ll w, cap, flow;
	Edge(int _u = 0, int _v = 0, int nxt = -1, ll _w = 1, ll _cap = 0)
	{
		u = _u;
		v = _v;
		w = _w;
		cap = _cap;
		flow = 0;
		next = nxt;
	}

	int operator<(const Edge &b) const
	{
		return w < b.w;
	}
};

const int maxn = 3e5 + 2, N = 2e6 + 1;
double eps = 1e-7, pi = acos(-1.0);
ull seed = 131, smod = (1LL << 32) - 267;

struct BIT
{
	int t[maxn*10], n;

	void add(int x, int d)
	{
		while (x <= n)
		{
			t[x] += d;
			x += lowbit(x);
		}
	}

	int sum(int x)
	{
		int ans = 0;
		while (x)
		{
			ans += t[x];
			x -= lowbit(x);
		}
		return ans;
	}
	int sum(int l, int r)
	{
		return sum(r) - sum(l - 1);
	}
}bit;

struct Seg
{
	int l, r, id;
	int operator<(const Seg &cmp) const
	{
		return r < cmp.r || (r == cmp.r && id < cmp.id);
	}
}a[maxn * 10];
int cnt;

int n, m, ans[maxn];

int main()
{
	bit.n = 1e6;
	ru(n, m);
	RP(i, 1, n)
	{
		++cnt;
		ru(a[cnt].l, a[cnt].r);
		a[cnt].id = 0;
	}
	int t, last, x;
	RP(i, 1, m)
	{
		last = 0;
		ru(t);
		while (t--)
		{
			++cnt;
			ru(x);
			a[cnt].l = last + 1; a[cnt].r = x - 1; a[cnt].id = i;
			last = x;
		}
		++cnt;
		a[cnt].l = last + 1; a[cnt].r = 1e6; a[cnt].id = i;
	}
	sort(a + 1, a + cnt + 1);
	RP(i, 1, cnt)
	{
		if (a[i].id)
		{
			if (a[i].l <= a[i].r)
				ans[a[i].id] += bit.sum(a[i].l, 1e6);
		}
		else
			bit.add(a[i].l, 1);
	}
	RP(i, 1, m) printf("%d\n", n-ans[i]);
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cstdlib>
#include <string>
#include <complex>
#include <bitset>
#include <cmath>
#include <stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<pii, int> piii;
typedef pair<pll, ll> plll;
typedef pair<pdd, double> pddd;
typedef complex<double> cpx;
#define mst(x,v) memset(x,v,sizeof(x))
#define rgs register
#define rp(k,x,v) for(rgs int k = x;k<v;++k)
#define rps(s) for(rgs int i = 0;s[i];++i)
#define RP(k,x,v) for(rgs int k = x;k<=v;++k)
#define lp(k,x,v) for(rgs int k = x;k>v;--k)
#define LP(k,x,v) for(rgs int k = x;k>=v;--k)
#define lowbit(x) (x&-x)
#define adde(u,v) edg[++ecnt]=Edge(u,v,g[u]),g[u]=ecnt
#define addew(u,v,w) edg[++ecnt]=Edge(u,v,g[u],w),g[u]=ecnt
#define addedg(u,v,w,cap) edg[++ecnt]=Edge(u,v,g[u],w,cap),g[u]=ecnt,edg[++ecnt]=Edge(v,u,g[v],-w,0),g[v]=ecnt
#define fson(x) for(rgs int i = g[x];~i;i=edg[i].next)
#define LB lower_bound
#define UB upper_bound
#define inp(n,a) RP(i,1,n) ru(a[i]);
#define mpt int mid = l+r>>1;
#define all(a) a.begin(),a.end()
#define inr (ql<=l && r<=qr)
#define upmax(a,b) a=max(a,b)
#define upmin(a,b) a=min(a,b)
const int INF = 1 << 29;
const ll LINF = 1LL << 60;
const double inf = 1e15;
ll mod = 1e9 + 7;
char READ_DATA;
int SIGNAL_INPUT;
template <typename Type>
inline Type ru(Type &v)
{
	SIGNAL_INPUT = 1;
	while ((READ_DATA = getchar()) < '0' || READ_DATA > '9')
		if (READ_DATA == '-')
			SIGNAL_INPUT = -1;
		else if (READ_DATA == EOF)
			return EOF;
	v = READ_DATA - '0';
	while ((READ_DATA = getchar()) >= '0' && READ_DATA <= '9')
		v = v * 10 + READ_DATA - '0';
	v *= SIGNAL_INPUT;
	return v;
}
inline ll modru(ll &v)
{
	ll p = 0;
	SIGNAL_INPUT = 1;
	while ((READ_DATA = getchar()) < '0' || READ_DATA > '9')
		if (READ_DATA == '-')
			SIGNAL_INPUT = -1;
		else if (READ_DATA == EOF)
			return EOF;
	p = v = READ_DATA - '0';
	while ((READ_DATA = getchar()) >= '0' && READ_DATA <= '9')
	{
		v = (v * 10 + READ_DATA - '0') % mod;
		p = (p * 10 + READ_DATA - '0') % (mod - 1);
	}
	v *= SIGNAL_INPUT;
	return p;
}
template<typename A, typename B > inline char ru(A&x, B&y) { if (ru(x) == EOF) return EOF; ru(y); return 2; }
template<typename A, typename B, typename C>inline char ru(A&x, B&y, C&z) { if (ru(x) == EOF) return EOF; ru(y); ru(z); return 3; }
template<typename A, typename B, typename C, typename D>inline char ru(A&x, B&y, C&z, D&w) { if (ru(x) == EOF) return EOF; ru(y); ru(z); ru(w); return 4; }

struct Edge
{
	int  u, v, next;
	ll w, cap, flow;
	Edge(int _u = 0, int _v = 0, int nxt = -1, ll _w = 1, ll _cap = 0)
	{
		u = _u;
		v = _v;
		w = _w;
		cap = _cap;
		flow = 0;
		next = nxt;
	}

	int operator<(const Edge &b) const
	{
		return w < b.w;
	}
};

const int maxn = 3e5 + 2, N = 2e6 + 1;
double eps = 1e-7, pi = acos(-1.0);
ull seed = 131, smod = (1LL << 32) - 267;

struct BIT
{
	int t[maxn*10], n;

	void add(int x, int d)
	{
		while (x <= n)
		{
			t[x] += d;
			x += lowbit(x);
		}
	}

	int sum(int x)
	{
		int ans = 0;
		while (x)
		{
			ans += t[x];
			x -= lowbit(x);
		}
		return ans;
	}
	int sum(int l, int r)
	{
		return sum(r) - sum(l - 1);
	}
}bit;

struct Seg
{
	int l, r, id;
	int operator<(const Seg &cmp) const
	{
		return r < cmp.r;
	}
}a[maxn << 2];
int cnt;

int n, m, ans[maxn];

int main()
{
	bit.n = 1e6;
	ru(n, m);
	RP(i, 1, n)
	{
		++cnt;
		ru(a[cnt].l, a[cnt].r);
		a[cnt].id = 0;
	}
	int t, last, x;
	RP(i, 1, m)
	{
		last = 0;
		ru(t);
		while (t--)
		{
			++cnt;
			ru(x);
			a[cnt].l = last + 1; a[cnt].r = x - 1; a[cnt].id = i;
			last = x;
		}
		++cnt;
		a[cnt].l = last + 1; a[cnt].r = 1e6; a[cnt].id = i;
	}
	sort(a + 1, a + cnt + 1);
	RP(i, 1, cnt)
	{
		if (a[i].id)
		{
			ans[a[i].id] += bit.sum(a[i].l, a[i].r);
		}
		else
			bit.add(a[i].l, 1);
	}
	RP(i, 1, m) printf("%d\n", n-ans[i]);
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cstdlib>
#include <string>
#include <complex>
#include <bitset>
#include <cmath>
#include <stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<pii, int> piii;
typedef pair<pll, ll> plll;
typedef pair<pdd, double> pddd;
typedef complex<double> cpx;
#define mst(x,v) memset(x,v,sizeof(x))
#define rgs register
#define rp(k,x,v) for(rgs int k = x;k<v;++k)
#define rps(s) for(rgs int i = 0;s[i];++i)
#define RP(k,x,v) for(rgs int k = x;k<=v;++k)
#define lp(k,x,v) for(rgs int k = x;k>v;--k)
#define LP(k,x,v) for(rgs int k = x;k>=v;--k)
#define lowbit(x) (x&-x)
#define adde(u,v) edg[++ecnt]=Edge(u,v,g[u]),g[u]=ecnt
#define addew(u,v,w) edg[++ecnt]=Edge(u,v,g[u],w),g[u]=ecnt
#define addedg(u,v,w,cap) edg[++ecnt]=Edge(u,v,g[u],w,cap),g[u]=ecnt,edg[++ecnt]=Edge(v,u,g[v],-w,0),g[v]=ecnt
#define fson(x) for(rgs int i = g[x];~i;i=edg[i].next)
#define LB lower_bound
#define UB upper_bound
#define inp(n,a) RP(i,1,n) ru(a[i]);
#define mpt int mid = l+r>>1;
#define all(a) a.begin(),a.end()
#define inr (ql<=l && r<=qr)
#define upmax(a,b) a=max(a,b)
#define upmin(a,b) a=min(a,b)
const int INF = 1 << 29;
const ll LINF = 1LL << 60;
const double inf = 1e15;
ll mod = 1e9 + 7;
char READ_DATA;
int SIGNAL_INPUT;
template <typename Type>
inline Type ru(Type &v)
{
	SIGNAL_INPUT = 1;
	while ((READ_DATA = getchar()) < '0' || READ_DATA > '9')
		if (READ_DATA == '-')
			SIGNAL_INPUT = -1;
		else if (READ_DATA == EOF)
			return EOF;
	v = READ_DATA - '0';
	while ((READ_DATA = getchar()) >= '0' && READ_DATA <= '9')
		v = v * 10 + READ_DATA - '0';
	v *= SIGNAL_INPUT;
	return v;
}
inline ll modru(ll &v)
{
	ll p = 0;
	SIGNAL_INPUT = 1;
	while ((READ_DATA = getchar()) < '0' || READ_DATA > '9')
		if (READ_DATA == '-')
			SIGNAL_INPUT = -1;
		else if (READ_DATA == EOF)
			return EOF;
	p = v = READ_DATA - '0';
	while ((READ_DATA = getchar()) >= '0' && READ_DATA <= '9')
	{
		v = (v * 10 + READ_DATA - '0') % mod;
		p = (p * 10 + READ_DATA - '0') % (mod - 1);
	}
	v *= SIGNAL_INPUT;
	return p;
}
template<typename A, typename B > inline char ru(A&x, B&y) { if (ru(x) == EOF) return EOF; ru(y); return 2; }
template<typename A, typename B, typename C>inline char ru(A&x, B&y, C&z) { if (ru(x) == EOF) return EOF; ru(y); ru(z); return 3; }
template<typename A, typename B, typename C, typename D>inline char ru(A&x, B&y, C&z, D&w) { if (ru(x) == EOF) return EOF; ru(y); ru(z); ru(w); return 4; }

struct Edge
{
	int  u, v, next;
	ll w, cap, flow;
	Edge(int _u = 0, int _v = 0, int nxt = -1, ll _w = 1, ll _cap = 0)
	{
		u = _u;
		v = _v;
		w = _w;
		cap = _cap;
		flow = 0;
		next = nxt;
	}

	int operator<(const Edge &b) const
	{
		return w < b.w;
	}
};

const int maxn = 3e5 + 2, N = 2e6 + 1;
double eps = 1e-7, pi = acos(-1.0);
ull seed = 131, smod = (1LL << 32) - 267;

struct BIT
{
	int t[maxn*10], n;

	void add(int x, int d)
	{
		while (x <= n)
		{
			t[x] += d;
			x += lowbit(x);
		}
	}

	int sum(int x)
	{
		int ans = 0;
		while (x)
		{
			ans += t[x];
			x -= lowbit(x);
		}
		return ans;
	}
	int sum(int l, int r)
	{
		return sum(r) - sum(l - 1);
	}
}bit;

struct Seg
{
	int l, r, id;
	int operator<(const Seg &cmp) const
	{
		return r < cmp.r;
	}
}a[maxn << 2];
int cnt;

int n, m, ans[maxn];

int main()
{
	bit.n = 1e6;
	ru(n, m);
	RP(i, 1, n)
	{
		++cnt;
		ru(a[cnt].l, a[cnt].r);
		a[cnt].id = 0;
	}
	int t, last, x;
	RP(i, 1, m)
	{
		last = 0;
		ru(t);
		while (t--)
		{
			++cnt;
			ru(x);
			a[cnt].l = last + 1; a[cnt].r = x - 1; a[cnt].id = i;
			last = x;
		}
		++cnt;
		a[cnt].l = last + 1; a[cnt].r = 1e6; a[cnt].id = i;
	}
	sort(a + 1, a + cnt + 1);
	RP(i, 1, cnt)
	{
		if (a[i].id && a[i].l <= a[i].r)
			ans[a[i].id] += bit.sum(a[i].l, 1e6);
		else
			bit.add(a[i].l, 1);
	}
	RP(i, 1, m) printf("%d\n", n-ans[i]);
}


#include<cstdio>
#include<algorithm>
using namespace std;

#define rep(i,__l,__r) for(signed i=(__l),i##_end_=(__r);i<=i##_end_;++i)
#define fep(i,__l,__r) for(signed i=(__l),i##_end_=(__r);i>=i##_end_;--i)
#define erep(i,u) for(signed i=tail[u],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define writc(a,b) fwrit(a),putchar(b)
#define mp(a,b) make_pair(a,b)
#define ft first
#define sd second
typedef long long LL;
// typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef unsigned uint;
#define Endl putchar('\n')
// #define int long long
// #define int unsigned
// #define int unsigned long long

#define cg (c=getchar())
template<class T>inline void read(T& x){
    char c;bool f=0;
    while(cg<'0'||'9'<c)f|=(c=='-');
    for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
    if(f)x=-x;
}
template<class T>inline T read(const T sample){
    T x=0;char c;bool f=0;
    while(cg<'0'||'9'<c)f|=(c=='-');
    for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
    return f?-x:x;
}
template<class T>void fwrit(const T x){//just short,int and long long
    if(x<0)return (void)(putchar('-'),fwrit(-x));
    if(x>9)fwrit(x/10);
    putchar(x%10^48);
}
template<class T>inline T Max(const T x,const T y){return x<y?y:x;}
template<class T>inline T Min(const T x,const T y){return x<y?x:y;}
template<class T>inline T fab(const T x){return x>0?x:-x;}
inline int gcd(const int a,const int b){return b?gcd(b,a%b):a;}
inline void getInv(int inv[],const int lim,const int MOD){
    inv[0]=inv[1]=1;for(int i=2;i<=lim;++i)inv[i]=1ll*inv[MOD%i]*(MOD-MOD/i)%MOD;
}
inline LL mulMod(const LL a,const LL b,const LL mod){
    return ((a*b-(LL)((long double)a/mod*b+1e-8)*mod)%mod+mod)%mod;
}

const int maxsum=3e5;
const int maxn=3e5;
const int maxq=3e5;
const int maxr=1e6;

struct BIT{
    int s[maxr+5];
    #define lowbit(i) ((i)&(-(i)))
    inline void Modify(const int pos,const int x){
        for(int i=pos;i<=maxr;i+=lowbit(i))s[i]+=x;
    }
    inline int Query(const int pos){
        int ret=0;
        for(int i=pos;i;i-=lowbit(i))ret+=s[i];
        return ret;
    }
}tre;

/** @param l,r 区间*/
/** @param id 询问的编号*/
struct node{int l,r,id;
    inline bool operator <(const node rhs)const{return l>rhs.l;}
};
/** @brief s : 初始给定的区间*/
node s[maxn*2+5];
/** @brief jzm : 离线下来的区间(也是一个巨佬)*/
node jzm[maxsum+5];
int sz;

int ans[maxq+5],n,q;

inline void Init(){
    n=read(1),q=read(1);
    int l,r;
    rep(i,1,n){
        l=read(1),r=read(1);
        s[i]=node{l,r,0};
    }
    int cnt,prel,pos;
    rep(i,1,q){
        cnt=read(1),prel=0;
        rep(j,1,cnt){
            pos=read(1);
            if(prel+1<=pos-1)jzm[++sz]=node{prel+1,pos-1,i};
            prel=pos;
        }if(prel+1<=maxr)jzm[++sz]=node{prel+1,maxr,i};
    }
}

inline void Get_ans(){
    sort(s+1,s+n+1);
    sort(jzm+1,jzm+sz+1);
    /** @brief pos : 当前 s 的位置在哪里了*/
    int pos=1;
    /** @brief now : 当前 jzm 的位置在哪里*/
    int now=1;
    while(now<=sz){
        // printf("Now pos == %d, now == %d\n",pos,now);
        while(pos<=n && s[pos].l>=jzm[now].l)tre.Modify(s[pos].r,1),++pos;
        ans[jzm[now].id]+=tre.Query(jzm[now].r)-tre.Query(jzm[now].l-1);
        ++now;
    }
}

inline void Writ_ans(){
    rep(i,1,q)writc(n-ans[i],'\n');
}

signed main(){
    Init();
    Get_ans();
    Writ_ans();
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;

#define rep(i,__l,__r) for(signed i=(__l),i##_end_=(__r);i<=i##_end_;++i)
#define fep(i,__l,__r) for(signed i=(__l),i##_end_=(__r);i>=i##_end_;--i)
#define erep(i,u) for(signed i=tail[u],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define writc(a,b) fwrit(a),putchar(b)
#define mp(a,b) make_pair(a,b)
#define ft first
#define sd second
typedef long long LL;
// typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef unsigned uint;
#define Endl putchar('\n')
// #define int long long
// #define int unsigned
// #define int unsigned long long

#define cg (c=getchar())
template<class T>inline void read(T& x){
    char c;bool f=0;
    while(cg<'0'||'9'<c)f|=(c=='-');
    for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
    if(f)x=-x;
}
template<class T>inline T read(const T sample){
    T x=0;char c;bool f=0;
    while(cg<'0'||'9'<c)f|=(c=='-');
    for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
    return f?-x:x;
}
template<class T>void fwrit(const T x){//just short,int and long long
    if(x<0)return (void)(putchar('-'),fwrit(-x));
    if(x>9)fwrit(x/10);
    putchar(x%10^48);
}
template<class T>inline T Max(const T x,const T y){return x<y?y:x;}
template<class T>inline T Min(const T x,const T y){return x<y?x:y;}
template<class T>inline T fab(const T x){return x>0?x:-x;}
inline int gcd(const int a,const int b){return b?gcd(b,a%b):a;}
inline void getInv(int inv[],const int lim,const int MOD){
    inv[0]=inv[1]=1;for(int i=2;i<=lim;++i)inv[i]=1ll*inv[MOD%i]*(MOD-MOD/i)%MOD;
}
inline LL mulMod(const LL a,const LL b,const LL mod){
    return ((a*b-(LL)((long double)a/mod*b+1e-8)*mod)%mod+mod)%mod;
}

const int maxsum=3e5;
const int maxn=3e5;
const int maxq=3e5;
const int maxr=1e6;

struct BIT{
    int s[maxr+5];
    #define lowbit(i) ((i)&(-(i)))
    inline void Modify(const int pos,const int x){
        for(int i=pos;i<=maxr;i+=lowbit(i))s[i]+=x;
    }
    inline int Query(const int pos){
        int ret=0;
        for(int i=pos;i;i-=lowbit(i))ret+=s[i];
        return ret;
    }
}tre;

/** @param l,r 区间*/
/** @param id 询问的编号*/
struct node{int l,r,id;
    inline bool operator <(const node rhs)const{return l>rhs.l;}
};
/** @brief s : 初始给定的区间*/
node s[maxn+5];
/** @brief jzm : 离线下来的区间(也是一个巨佬)*/
node jzm[maxsum*2+5];
int sz;

int ans[maxq+5],n,q;

inline void Init(){
    n=read(1),q=read(1);
    int l,r;
    rep(i,1,n){
        l=read(1),r=read(1);
        s[i]=node{l,r,0};
    }
    int cnt,prel,pos;
    rep(i,1,q){
        cnt=read(1),prel=0;
        rep(j,1,cnt){
            pos=read(1);
            if(prel+1<=pos-1)jzm[++sz]=node{prel+1,pos-1,i};
            prel=pos;
        }if(prel+1<=maxr)jzm[++sz]=node{prel+1,maxr,i};
    }
}

inline void Get_ans(){
    sort(s+1,s+n+1);
    sort(jzm+1,jzm+sz+1);
    /** @brief pos : 当前 s 的位置在哪里了*/
    int pos=1;
    /** @brief now : 当前 jzm 的位置在哪里*/
    int now=1;
    while(now<=sz){
        // printf("Now pos == %d, now == %d\n",pos,now);
        while(pos<=n && s[pos].l>=jzm[now].l)tre.Modify(s[pos].r,1),++pos;
        ans[jzm[now].id]+=tre.Query(jzm[now].r)-tre.Query(jzm[now].l-1);
        ++now;
    }
}

inline void Writ_ans(){
    rep(i,1,q)writc(n-ans[i],'\n');
}

signed main(){
    Init();
    Get_ans();
    Writ_ans();
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;

#define rep(i,__l,__r) for(signed i=(__l),i##_end_=(__r);i<=i##_end_;++i)
#define fep(i,__l,__r) for(signed i=(__l),i##_end_=(__r);i>=i##_end_;--i)
#define erep(i,u) for(signed i=tail[u],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define writc(a,b) fwrit(a),putchar(b)
#define mp(a,b) make_pair(a,b)
#define ft first
#define sd second
typedef long long LL;
// typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef unsigned uint;
#define Endl putchar('\n')
#define int long long
// #define int unsigned
// #define int unsigned long long

#define cg (c=getchar())
template<class T>inline void read(T& x){
    char c;bool f=0;
    while(cg<'0'||'9'<c)f|=(c=='-');
    for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
    if(f)x=-x;
}
template<class T>inline T read(const T sample){
    T x=0;char c;bool f=0;
    while(cg<'0'||'9'<c)f|=(c=='-');
    for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
    return f?-x:x;
}
template<class T>void fwrit(const T x){//just short,int and long long
    if(x<0)return (void)(putchar('-'),fwrit(-x));
    if(x>9)fwrit(x/10);
    putchar(x%10^48);
}
template<class T>inline T Max(const T x,const T y){return x<y?y:x;}
template<class T>inline T Min(const T x,const T y){return x<y?x:y;}
template<class T>inline T fab(const T x){return x>0?x:-x;}
inline int gcd(const int a,const int b){return b?gcd(b,a%b):a;}
inline void getInv(int inv[],const int lim,const int MOD){
    inv[0]=inv[1]=1;for(int i=2;i<=lim;++i)inv[i]=1ll*inv[MOD%i]*(MOD-MOD/i)%MOD;
}
inline LL mulMod(const LL a,const LL b,const LL mod){
    return ((a*b-(LL)((long double)a/mod*b+1e-8)*mod)%mod+mod)%mod;
}

const int maxsum=3e5;
const int maxn=3e5;
const int maxq=3e5;
const int maxr=1e6;

struct BIT{
    int s[maxr+5];
    #define lowbit(i) ((i)&(-(i)))
    inline void Modify(const int pos,const int x){
        for(int i=pos;i<=maxr;i+=lowbit(i))s[i]+=x;
    }
    inline int Query(const int pos){
        int ret=0;
        for(int i=pos;i;i-=lowbit(i))ret+=s[i];
        return ret;
    }
}tre;

/** @param l,r 区间*/
/** @param id 询问的编号*/
struct node{int l,r,id;
    inline bool operator <(const node rhs)const{return l>rhs.l;}
};
/** @brief s : 初始给定的区间*/
node s[maxn*2+5];
/** @brief jzm : 离线下来的区间(也是一个巨佬)*/
node jzm[maxsum+5];
int sz;

int ans[maxq+5],n,q;

inline void Init(){
    n=read(1ll),q=read(1ll);
    int l,r;
    rep(i,1,n){
        l=read(1ll),r=read(1ll);
        s[i]=node{l,r,0};
    }
    int cnt,prel,pos;
    rep(i,1,q){
        cnt=read(1ll),prel=0;
        rep(j,1,cnt){
            pos=read(1ll);
            if(prel+1<=pos-1)jzm[++sz]=node{prel+1,pos-1,i};
            prel=pos;
        }if(prel+1<=maxr)jzm[++sz]=node{prel+1,maxr,i};
    }
}

inline void Get_ans(){
    sort(s+1,s+n+1);
    sort(jzm+1,jzm+sz+1);
    /** @brief pos : 当前 s 的位置在哪里了*/
    int pos=1;
    /** @brief now : 当前 jzm 的位置在哪里*/
    int now=1;
    while(now<=sz){
        // printf("Now pos == %d, now == %d\n",pos,now);
        while(pos<=n && s[pos].l>=jzm[now].l)tre.Modify(s[pos].r,1),++pos;
        ans[jzm[now].id]+=tre.Query(jzm[now].r)-tre.Query(jzm[now].l-1);
        ++now;
    }
}

inline void Writ_ans(){
    rep(i,1,q)writc(n-ans[i],'\n');
}

signed main(){
    Init();
    Get_ans();
    Writ_ans();
    return 0;
}


#include <bits/stdc++.h>
#define maxn 101000
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
map<int,int >mp;
int l[maxn], r[maxn], n, m, t, a;
int main(){
    scanf("%d%d", &n, &m);
    for(int i=0;i<n;i++) scanf("%d%d", &l[i], &r[i]);
    while(m--){
        scanf("%d", &t);
        for(int i=0;i<t;i++){
            scanf("%d", &a);
            int t1 = upper_bound(l, l+n, a)-l-1;
            int t2 = lower_bound(r, r+n, a)-r;
            //cout<<t1<<" "<<t2<<" "<<a<<endl;
            if(t1 == t2) mp[t1] = 1;
        }
        cout<<mp.size()<<endl;
        mp.clear();
    }
    return 0;
}


#include <bits/stdc++.h>
#define maxn 101000
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
struct node{
    int l,r;
}q[maxn];
map<int,int >mp;
int l[maxn], r[maxn], n, m, t, a;
int cmp(node aa,node bb){
    return aa.r<bb.l;
}
int main(){
    scanf("%d%d", &n, &m);
    for(int i=0;i<n;i++) scanf("%d%d", &q[i].l, &q[i].r);
    sort(q, q+n, cmp);
    for(int i=0;i<n;i++)
        l[i] = q[i].l, r[i] = q[i].r;
    while(m--){
        scanf("%d", &t);
        for(int i=0;i<t;i++){
            scanf("%d", &a);
            int t1 = upper_bound(l, l+n, a)-l-1;
            int t2 = lower_bound(r, r+n, a)-r;
            //cout<<t1<<" "<<t2<<" "<<a<<endl;
            if(t1 == t2) mp[t1] = 1;
        }
        cout<<mp.size()<<endl;
        mp.clear();
    }
    return 0;
}


#include <bits/stdc++.h>
#define maxn 1001000
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
int a[maxn], b[maxn];
map<pair<int ,int >, int>mp;
void update(int *c,int a,int b){
    for(int i=a;i<maxn;i+=i&(-i)) c[i] += b;
}
int f(int *c,int a){
    int sum = 0;
    for(int i=a;i>=1;i-=i&(-i)) sum += c[i];
    return sum;
}
int main(){
    int n, m, l, r, t;
    scanf("%d%d", &n, &m);
    for(int i=0;i<n;i++){
        scanf("%d%d", &l, &r);
        update(a, l, 1);
        update(b, r+1, -1);
    }
    for(int i=0;i<m;i++){
        scanf("%d", &t);
        mp.clear();
        for(int i=0;i<t;i++){
            scanf("%d", &n);
            int l1 = f(a, n);
            int l2 = f(b, n);
            //cout<<l1<<" "<<l2<<endl;
            mp[make_pair(l1, l2)] = 1;
        }
        int ans = 0;
        for(auto j:mp)
            ans += j.first.first+j.first.second;
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define maxn 1001000
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
struct node{
    int l,r, id;
}a[maxn];
int c[maxn], b[maxn], n, m, num, cnt, ans[maxn];
int cmp(node aa,node bb){
    if(aa.l == bb.l){
        if(aa.r == bb.r) return aa.id<bb.id;
        return aa.r<bb.r;
    }
    return aa.l>bb.l;
}
int sum(int x){
    int sum = 0;
    for(int i=x;i>0;i-=i&(-i)) sum += c[i];
    return sum;
}
void update(int x){
    for(int i=x;i<maxn;i+=i&(-i)) c[i]++;
}
int main(){
    scanf("%d%d", &n, &m);
    for(int i=0;i<n;i++)
        scanf("%d%d", &a[i].l, &a[i].r), a[i].id = 0;
    num = n;
    for(int i=1;i<=m;i++){
        scanf("%d", &cnt);
        b[0] = 0;b[cnt+1] = 1e6+10;
        for(int j=1;j<=cnt;j++) scanf("%d", &b[j]);
        for(int j=0;j<=cnt;j++){
            if(b[j]+1<=b[j+1]-1)
            a[num++] = (node){b[j]+1, b[j+1]-1, i};
        }
    }
    sort(a, a+num, cmp);
    for(int i=0;i<num;i++){
        //cout<<a[i].id<<" "<<a[i].l<<" "<<a[i].r<<endl;
        if(a[i].id == 0) update(a[i].r);
        else ans[a[i].id] += sum(a[i].r);
    }
    for(int i=1;i<=m;i++)
        cout<<n-ans[i]<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 1000000;

vector<int> t[4 * N + 10];

void add(int v, int l, int r, int p, int val) {
  if (r < p || l > p) {
    return;
  }
  if (l == r) {
    t[v].push_back(val);
    return;
  }

  add(2 * v, l, (l + r) / 2, p, val);
  add(2 * v + 1, (l + r) / 2 + 1, r, p, val);

  t[v].clear();
  merge(t[2 * v].begin(), t[2 * v].end(), t[2 * v + 1].begin(), t[2 * v + 1].end(), back_inserter(t[v]));
}

int get(int v, int dl, int dr, int l, int r) {
  if (dr < l || r < dl || t[v].empty()) {
    return 0;
  }
  if (l <= dl && dr <= r) {
    return upper_bound(t[v].begin(), t[v].end(), r) - t[v].begin();
  }
  return get(2 * v, dl, (dl + dr) / 2, l, r) + get(2 * v + 1, (dl + dr) / 2 + 1, dr, l, r);
}

int n, m, p[N];

vector<int> seg[N];

int main() {
  scanf("%d%d", &n, &m);

  for (int i = 1; i <= n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    seg[l].push_back(r);
  }

  for (int i = 1; i <= N; i++) {
    sort(seg[i].begin(), seg[i].end());
    for (int j : seg[i]) {
      add(1, 1, N, i, j);
    }
  }

  for (int i = 1; i <= m; i++) {
    int cnt;
    scanf("%d", &cnt);
    for (int j = 1; j <= cnt; j++) {
      scanf("%d", &p[j]);
    }
    p[cnt + 1] = N + 1;

    int segCnt = 0;

    for (int j = 0; j <= cnt; j++) {
      segCnt += get(1, 1, N, p[j] + 1, p[j + 1] - 1);
    }

    printf("%d\n", n - segCnt);
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 1000000;

vector<int> t[4 * N + 10];

void add(int v, int l, int r, int p, int val) {
  if (r < p || l > p) {
    return;
  }
  if (l == r) {
    t[v].push_back(val);
    sort(t[v].begin(), t[v].end());
    return;
  }

  add(2 * v, l, (l + r) / 2, p, val);
  add(2 * v + 1, (l + r) / 2 + 1, r, p, val);

  t[v].clear();
  merge(t[2 * v].begin(), t[2 * v].end(), t[2 * v + 1].begin(), t[2 * v + 1].end(), back_inserter(t[v]));
}

int get(int v, int dl, int dr, int l, int r) {
  if (dr < l || r < dl || t[v].empty()) {
    return 0;
  }
  if (l <= dl && dr <= r) {
    return upper_bound(t[v].begin(), t[v].end(), r) - t[v].begin();
  }
  return get(2 * v, dl, (dl + dr) / 2, l, r) + get(2 * v + 1, (dl + dr) / 2 + 1, dr, l, r);
}

int n, m, p[N];

int main() {
  scanf("%d%d", &n, &m);

  for (int i = 1; i <= n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    add(1, 1, N, l, r);
  }

  for (int i = 1; i <= m; i++) {
    int cnt;
    scanf("%d", &cnt);
    for (int j = 1; j <= cnt; j++) {
      scanf("%d", &p[j]);
    }
    p[cnt + 1] = N + 1;

    int segCnt = 0;

    for (int j = 0; j <= cnt; j++) {
      segCnt += get(1, 1, N, p[j] + 1, p[j + 1] - 1);
    }

    printf("%d\n", n - segCnt);
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 1000000;

multiset<int> t[4 * N + 10];

void add(int v, int l, int r, int p, int val) {
  if (r < p || l > p) {
    return;
  }
  if (l == r) {
    t[v].insert(val);
    return;
  }

  add(2 * v, l, (l + r) / 2, p, val);
  add(2 * v + 1, (l + r) / 2 + 1, r, p, val);

  t[v].clear();

  for (int i : t[2 * v]) {
    t[v].insert(i);
  }
  for (int i : t[2 * v + 1]) {
    t[v].insert(i);
  }
}

int get(int v, int dl, int dr, int l, int r) {
  if (dr < l || r < dl || t[v].empty()) {
    return 0;
  }
  if (l <= dl && dr <= r && *t[v].rbegin() <= r) {
    return t[v].size();
  }
  return get(2 * v, dl, (dl + dr) / 2, l, r) + get(2 * v + 1, (dl + dr) / 2 + 1, dr, l, r);
}

int n, m, p[N];

int main() {
  scanf("%d%d", &n, &m);

  for (int i = 1; i <= n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    add(1, 1, N, l, r);
  }

  for (int i = 1; i <= m; i++) {
    int cnt;
    scanf("%d", &cnt);
    for (int j = 1; j <= cnt; j++) {
      scanf("%d", &p[j]);
    }
    p[cnt + 1] = N + 1;

    int segCnt = 0;

    for (int j = 0; j <= cnt; j++) {
      segCnt += get(1, 1, N, p[j] + 1, p[j + 1] - 1);
    }

    printf("%d\n", n - segCnt);
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 1000000;

vector<int> t[4 * N + 10];

void add(int v, int l, int r, int p, int val) {
  if (r < p || l > p) {
    return;
  }
  if (l == r) {
    t[v].push_back(val);
    return;
  }

  add(2 * v, l, (l + r) / 2, p, val);
  add(2 * v + 1, (l + r) / 2 + 1, r, p, val);

  t[v].clear();
  merge(t[2 * v].begin(), t[2 * v].end(), t[2 * v + 1].begin(), t[2 * v + 1].end(), back_inserter(t[v]));
}

int get(int v, int dl, int dr, int l, int r) {
  if (dr < l || r < dl || t[v].empty()) {
    return 0;
  }
  if (l <= dl && dr <= r) {
    return upper_bound(t[v].begin(), t[v].end(), r) - t[v].begin();
  }
  return get(2 * v, dl, (dl + dr) / 2, l, r) + get(2 * v + 1, (dl + dr) / 2 + 1, dr, l, r);
}

int n, m, p[N];

int main() {
  scanf("%d%d", &n, &m);

  for (int i = 1; i <= n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    add(1, 1, N, l, r);
  }

  for (int i = 1; i <= m; i++) {
    int cnt;
    scanf("%d", &cnt);
    for (int j = 1; j <= cnt; j++) {
      scanf("%d", &p[j]);
    }
    p[cnt + 1] = N + 1;

    int segCnt = 0;

    for (int j = 0; j <= cnt; j++) {
      segCnt += get(1, 1, N, p[j] + 1, p[j + 1] - 1);
    }

    printf("%d\n", n - segCnt);
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 1000000;

vector<int> t[4 * N + 10];

void add(int v, int l, int r, int p, int val) {
  if (r < p || l > p) {
    return;
  }
  if (l == r) {
    t[v].push_back(val);
    return;
  }

  add(2 * v, l, (l + r) / 2, p, val);
  add(2 * v + 1, (l + r) / 2 + 1, r, p, val);

  t[v].push_back(val);
}

int get(int v, int dl, int dr, int l, int r) {
  if (dr < l || r < dl || t[v].empty()) {
    return 0;
  }
  if (l <= dl && dr <= r) {
    return upper_bound(t[v].begin(), t[v].end(), r) - t[v].begin();
  }
  return get(2 * v, dl, (dl + dr) / 2, l, r) + get(2 * v + 1, (dl + dr) / 2 + 1, dr, l, r);
}

int n, m, p[N];

vector<int> seg[N];

int main() {
  scanf("%d%d", &n, &m);

  for (int i = 1; i <= n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    add(1, 1, N, l, r);
  }

  for (auto &i : t) {
    sort(i.begin(), i.end());
  }

  for (int i = 1; i <= m; i++) {
    int cnt;
    scanf("%d", &cnt);
    for (int j = 1; j <= cnt; j++) {
      scanf("%d", &p[j]);
    }
    p[cnt + 1] = N + 1;

    int segCnt = 0;

    for (int j = 0; j <= cnt; j++) {
      segCnt += get(1, 1, N, p[j] + 1, p[j + 1] - 1);
    }

    printf("%d\n", n - segCnt);
  }

  return 0;
}


  //File Name: cf369E.cpp
  //Author: long
  //Mail: 736726758@qq.com
  //Created Time: 2016年04月14日 星期四 22时36分22秒

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cstdlib>

using namespace std;

const int MAXN = 100000 + 3;
const int N = 1000000;

struct Line{
	int l,r,id;
};
Line p[MAXN];
Line q[N * 10];
int ans[MAXN];
int bit[N + 3];
int tot;

inline int lb(int x){
	return x & (-x);
}

void update(int x,int add){
	while(x <= N){
		bit[x] += add;
		x += lb(x);
	}
}

int query(int x){
	int res = 0;
	while(x > 0){
		res += bit[x];
		x -= lb(x);
	}
	return res;
}

bool cmp(Line x,Line y){
	if(x.r == y.r)
		return x.l < y.l;
	return x.r < y.r;
}

void solve(int n,int m){
	sort(p,p + n,cmp);
	sort(q,q + tot,cmp);
	memset(ans,0,sizeof ans);
	int pos = 0;
	for(int i=0;i<tot;i++){
		while(pos < n && p[pos].r <= q[i].r){
			update(p[pos].l,1);
			pos++;
		}
		ans[q[i].id] += query(q[i].r) - query(q[i].l - 1);
	}
	for(int i=0;i<m;i++){
		ans[i] = n - ans[i];
	}
	for(int i=0;i<m;i++){
		printf("%d\n",ans[i]);
	}
	return ;
}

int main(){
	int n,m;
	tot = 0;
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d %d",&p[i].l,&p[i].r);
	}
	for(int i=0,num,pre,x;i<m;i++){
		scanf("%d",&num);
		pre = 0;
		for(int j=0;j<num;j++){
			scanf("%d",&x);
			if(pre + 1 <= x - 1){
				q[tot].l = pre + 1;
				q[tot].r = x - 1;
				q[tot++].id = i;
			}
			pre = x;
		}
		if(pre + 1 <= N){
			q[tot].l = pre + 1;
			q[tot].r = N;
			q[tot++].id = i;
		}
	}
	solve(n,m);
	return 0;
}


  //File Name: cf369E.cpp
  //Author: long
  //Mail: 736726758@qq.com
  //Created Time: 2016年04月14日 星期四 22时36分22秒

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cstdlib>

using namespace std;

const int MAXN = 100000 + 3;
const int N = 1000000;

struct Line{
	int l,r,id;
};
Line p[MAXN];
Line q[N * 10];
int ans[MAXN];
int bit[N + 5];
int tot;

inline int lb(int x){
	return x & (-x);
}

void update(int x,int add){
	while(x <= N){
		bit[x] += add;
		x += lb(x);
	}
}

int query(int x){
	int res = 0;
	while(x > 0){
		res += bit[x];
		x -= lb(x);
	}
	return res;
}

bool cmp(Line x,Line y){
	if(x.r == y.r)
		return x.l < y.l;
	return x.r < y.r;
}

void solve(int n,int m){
	sort(p,p + n,cmp);
	sort(q,q + tot,cmp);
	memset(ans,0,sizeof ans);
	int pos = 0;
	for(int i=0;i<tot;i++){
		while(pos < n && p[pos].r <= q[i].r){
			update(p[pos].l,1);
			pos++;
		}
		ans[q[i].id] += query(q[i].r) - query(q[i].l - 1);
	}

	for(int i=0;i<m;i++){
		printf("%d\n",n - ans[i]);
	}
	return ;
}

int main(){
	int n,m;
	tot = 0;
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d %d",&p[i].l,&p[i].r);
	}
	for(int i=0,num,pre,x;i<m;i++){
		scanf("%d",&num);
		pre = 0;
		while(num--){
			scanf("%d",&x);
			if(pre + 1 <= x - 1){
				q[tot].l = pre + 1;
				q[tot].r = x - 1;
				q[tot++].id = i;
			}
			pre = x;
		}
		if(pre + 1 <= N){
			q[tot].l = pre + 1;
			q[tot].r = N;
			q[tot++].id = i;
		}
	}
	solve(n,m);
	return 0;
}


  //File Name: cf369E.cpp
  //Author: long
  //Mail: 736726758@qq.com
  //Created Time: 2016年04月14日 星期四 22时36分22秒

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cstdlib>

using namespace std;

const int MAXN = 100000 + 3;
const int N = 1000000;

struct Line{
	int l,r,id;
};
Line p[MAXN];
Line q[MAXN];
int ans[MAXN];
int bit[N + 3];
int tot;

inline int lb(int x){
	return x & (-x);
}

void update(int x,int add){
	while(x <= N){
		bit[x] += add;
		x += lb(x);
	}
}

int query(int x){
	int res = 0;
	while(x > 0){
		res += bit[x];
		x -= lb(x);
	}
	return res;
}

bool cmp(Line x,Line y){
	if(x.r == y.r)
		return x.l < y.l;
	return x.r < y.r;
}

void solve(int n,int m){
	sort(p,p + n,cmp);
	sort(q,q + tot,cmp);
	memset(ans,0,sizeof ans);
	int pos = 0;
	for(int i=0;i<tot;i++){
		while(pos < n && p[pos].r <= q[i].r){
			update(p[pos].l,1);
			pos++;
		}
		ans[q[i].id] += query(q[i].r) - query(q[i].l - 1);
	}
	for(int i=0;i<m;i++){
		ans[i] = n - ans[i];
	}
	for(int i=0;i<m;i++){
		printf("%d\n",ans[i]);
	}
	return ;
}

int main(){
	int n,m;
	tot = 0;
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d %d",&p[i].l,&p[i].r);
	}
	for(int i=0,num,pre,x;i<m;i++){
		scanf("%d",&num);
		pre = 0;
		for(int j=0;j<num;j++){
			scanf("%d",&x);
			if(pre + 1 <= x - 1){
				q[tot].l = pre + 1;
				q[tot].r = x - 1;
				q[tot++].id = i;
			}
			pre = x;
		}
		if(pre + 1 <= N){
			q[tot].l = pre + 1;
			q[tot].r = N;
			q[tot++].id = i;
		}
	}
	solve(n,m);
	return 0;
}


  //File Name: cf369E.cpp
  //Author: long
  //Mail: 736726758@qq.com
  //Created Time: 2016年04月14日 星期四 22时36分22秒

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cstdlib>

using namespace std;

const int MAXN = 100000 + 3;
const int N = 1000000;

struct Line{
	int l,r,id;
};
Line p[MAXN];
Line q[N];
int ans[MAXN];
int bit[N + 3];
int tot;

inline int lb(int x){
	return x & (-x);
}

void update(int x,int add){
	while(x <= N){
		bit[x] += add;
		x += lb(x);
	}
}

int query(int x){
	int res = 0;
	while(x > 0){
		res += bit[x];
		x -= lb(x);
	}
	return res;
}

bool cmp(Line x,Line y){
	if(x.r == y.r)
		return x.l < y.l;
	return x.r < y.r;
}

void solve(int n,int m){
	sort(p,p + n,cmp);
	sort(q,q + tot,cmp);
	memset(ans,0,sizeof ans);
	int pos = 0;
	for(int i=0;i<tot;i++){
		while(pos < n && p[pos].r <= q[i].r){
			update(p[pos].l,1);
			pos++;
		}
		ans[q[i].id] += query(q[i].r) - query(q[i].l - 1);
	}
	for(int i=0;i<m;i++){
		ans[i] = n - ans[i];
	}
	for(int i=0;i<m;i++){
		printf("%d\n",ans[i]);
	}
	return ;
}

int main(){
	int n,m;
	tot = 0;
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d %d",&p[i].l,&p[i].r);
	}
	for(int i=0,num,pre,x;i<m;i++){
		scanf("%d",&num);
		pre = 0;
		for(int j=0;j<num;j++){
			scanf("%d",&x);
			if(pre + 1 <= x - 1){
				q[tot].l = pre + 1;
				q[tot].r = x - 1;
				q[tot++].id = i;
			}
			pre = x;
		}
		if(pre + 1 <= N){
			q[tot].l = pre + 1;
			q[tot].r = N;
			q[tot++].id = i;
		}
	}
	solve(n,m);
	return 0;
}


  //File Name: cf369E.cpp
  //Author: long
  //Mail: 736726758@qq.com
  //Created Time: 2016年04月14日 星期四 22时36分22秒

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cstdlib>

using namespace std;

const int MAXN = 300000 + 3;
const int N = 1000000;

struct Line{
	int l,r,id;
};
Line p[MAXN];
Line q[N * 10];
int ans[MAXN];
int bit[N + 5];
int tot;

inline int lb(int x){
	return x & (-x);
}

void update(int x,int add){
	while(x <= N){
		bit[x] += add;
		x += lb(x);
	}
}

int query(int x){
	int res = 0;
	while(x > 0){
		res += bit[x];
		x -= lb(x);
	}
	return res;
}

bool cmp(Line x,Line y){
	if(x.r == y.r)
		return x.l < y.l;
	return x.r < y.r;
}

void solve(int n,int m){
	sort(p,p + n,cmp);
	sort(q,q + tot,cmp);
	memset(ans,0,sizeof ans);
	int pos = 0;
	for(int i=0;i<tot;i++){
		while(pos < n && p[pos].r <= q[i].r){
			update(p[pos].l,1);
			pos++;
		}
		ans[q[i].id] += query(q[i].r) - query(q[i].l - 1);
	}

	for(int i=0;i<m;i++){
		printf("%d\n",n - ans[i]);
	}
	return ;
}

int main(){
	int n,m;
	tot = 0;
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d %d",&p[i].l,&p[i].r);
	}
	for(int i=0,num,pre,x;i<m;i++){
		scanf("%d",&num);
		pre = 0;
		while(num--){
			scanf("%d",&x);
			if(pre + 1 <= x - 1){
				q[tot].l = pre + 1;
				q[tot].r = x - 1;
				q[tot++].id = i;
			}
			pre = x;
		}
		if(pre + 1 <= N){
			q[tot].l = pre + 1;
			q[tot].r = N;
			q[tot++].id = i;
		}
	}
	solve(n,m);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double DB;
typedef long double LDB;

#define input(f)\
        freopen(f,"r",stdin)
#define output(f)\
        freopen(f,"w",stdout)
#define space " "
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define ALL(x) x.begin(), x.end()
#define rALL(x) x.rbegin(), x.rend()

template<class T>
T sqr(T x) { return x * x; }

template<class T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

template<class T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<class T>
bool isSquare(T x) {
    T y = sqrt(x + 0.5);
    return (y * y) == x;
}

template<class T1, class T2>
T1 eqMin(T1 &x, const T2 &y) {
    if (T1(y) < x) return x = y;
    return x;
}

template<class T1, class T2>
T1 eqMax(T1 &x, const T2 &y) {
    if (T1(y) > x) return x = y;
    return x;
}

const double PI = acos(-1);
const double EPS = 1e-8;
const int INF = (int) 2e9;
const ull LINF = (ull) 2e18;
const ll MOD = (ll) 1e9 + 7;
const int MAXN = (int) 1e6;

template<class T>
class FenwickTree {
    vector<T> tree;

    int F(int i) {
        return i & (i + 1);
    }

public:
    FenwickTree(const vector<T> &V) {
        tree = vector<T>(V.size());

        for (int i = 0; i < tree.size(); i++) {
            int index = i;
            modify(index, V[i]);
        }
    }

    void modify(int index, const T &value) {
        while (index < tree.size()) {
            tree[index] += value;
            index |= index + 1;
        }
    }

    T Request(int R) {
        T res = T(0);
        while (R >= 0) {
            res += tree[R];
            R = F(R) - 1;
        }
        return res;
    }

    T Request(int L, int R) {
        return Request(R) - Request(L - 1);
    }
};

ll n, q;
vector<pair<int, int> > cuts;
vector<int> cutsHelp[MAXN + 10];
vector<int> Q[MAXN + 10];
vector<pair<int, int> > QHelp[MAXN + 10];
FenwickTree<int> tree(vector<int>(MAXN + 10, 0));
vector<int> ans(MAXN + 10);

void init() {
    cin >> n >> q;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        cuts.push_back({x, y});
        cutsHelp[y].push_back(x);
    }

    for (int i = 0; i < q; i++) {
        int cnt;
        cin >> cnt;
        Q[i].push_back(0);
        for (int j = 0; j < cnt; j++) {
            int kek;
            cin >> kek;
            Q[i].push_back(kek);
        }
        Q[i].push_back(MAXN + 2);
    }
}

void solve() {
    for (int i = 0; i < q; i++) {
        for (int j = 0; j < Q[i].size() - 1; j++) {
            int le = Q[i][j] + 1, ri = Q[i][j + 1] - 1;
            QHelp[ri].push_back({le, i});
        }
    }

    for (int i = 0; i < MAXN + 5; i++) {
        //write left bounds of init
        for (int j = 0; j < cutsHelp[i].size(); j++) {
            tree.modify(cutsHelp[i][j], 1);
        }
        //sum in cut
        for (int j = 0; j < QHelp[i].size(); j++) {
            ans[QHelp[i][j].second] += tree.Request(QHelp[i][j].first, i);
        }
    }
    for (int i = 0; i < q; i++) {
        cout << n - ans[i] << endl;
    }

}

int main() {
    ios_base::sync_with_stdio(false);
    init();
    solve();
    return 0;
}


#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <set>

using namespace std;

const int N = 300500;
vector<pair<int, int> > a;
vector< int > tree[4 * N];
vector<int> xx;
int n;

inline int readInt()
{
	int s = 1, x = 0, c = getc(stdin);
	while (c <= 32)
		c = getc(stdin);
	if (c == '-')
		s = -1, c = getc(stdin);
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getc(stdin);
	return x * s;
}

inline void writeInt(int x)
{
	if (x < 0)
		putc('-', stdout), x = -x;

	char s[20];
	int n = 0;
	while (x || !n)
		s[n++] = '0' + x % 10, x /= 10;
	while (n--)
		putc(s[n], stdout);
}

inline void build(int sz)
{

	for (int i = sz - 1; i < sz + n - 1; i++)
		tree[i].push_back(a[i - sz + 1].second);
	for (int v = sz - 2; v >= 0; v--)
	{
		tree[v].resize(tree[2 * v + 1].size() + tree[2 * v + 2].size());
		merge(tree[2 * v + 1].begin(), tree[2 * v + 1].end(), tree[2 * v + 2].begin(), tree[2 * v + 2].end(), tree[v].begin());
	}
}

//inline void add(int l, int r, int k, int v)
//{
//	if (l + 1 == r)
//	{
//		tree[v].push_back(a[k].second);
//		return;
//	}
//	int m = (l + r)/2;
//	if (m > k)
//		add(l, m, k, 2 * v + 1);
//	else
//		add(m, r, k, 2 * v + 2);
//	tree[v].resize(tree[2 * v + 1].size() + tree[2 * v + 2].size());
//	merge(tree[2 * v + 1].begin(), tree[2 * v + 1].end(), tree[2 * v + 2].begin(), tree[2 * v + 2].end(), tree[v].begin());
//	return;
//}

inline int getans(int l, int r, int lv, int rv, int v, int y0, int y1)
{
	if (lv == r)
		return 0;
	if (l == lv && r == rv)
	{
		return upper_bound(tree[v].begin(), tree[v].end(), y1 - 1) - lower_bound(tree[v].begin(), tree[v].end(), y0 + 1);
	}
	int m = (l + r) / 2;
	if (m >= rv)
		return getans(l, m, lv, rv, 2 * v + 1, y0, y1);
	if (m <= lv)
		return getans(m, r, lv, rv, 2 * v + 2, y0, y1);
	return getans(l, m, lv, m, 2 * v + 1, y0, y1) + getans(m, r, m, rv, 2 * v + 2, y0, y1);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

//	freopen("stars.in", "r", stdin);
	//freopen("stars.out", "w", stdout);

	int m;

	//cin >> n >> m;
	//scanf("%d%d", &n, &m);
	n = readInt();
	m = readInt();

	a.resize(n);

	int x, y;
	for (int i = 0; i < n; ++i)
	{
		//cin >> x >> y;
		//scanf("%d%d", &x, &y);
		x = readInt();
		y = readInt();
		a[i] = { x, y };
	}

	sort(a.begin(), a.end());
	xx.resize(n);
	for (int i = 0; i < n; ++i)
		xx[i] = a[i].first;

	int sz = 1;
	while (sz < n)
		sz *= 2;

	build(sz);

	int x0, y0, x1, y1, lv, rv;
	int k, ans;

	for (int i = 0; i < m; ++i)
	{
		cin >> k;
		x0 = 0;
		ans = 0;
		for (int j = 0; j < k; ++j)
		{
			cin >> x1;
			lv = distance(xx.begin(), lower_bound(xx.begin(), xx.end(), x0+1));
			rv = distance(xx.begin(), upper_bound(xx.begin(), xx.end(), x1-1));

			/*if (lv == rv)
				rv++;*/
				//cout << getans(0, n, lv, rv, 0, y0, y1) << '\n';
				//printf("%d\n", getans(0, n, lv, rv, 0, y0, y1));
			ans += getans(0, sz, lv, rv, 0, x0, x1);
			x0 = x1;
		}
		x1 = 1000010;
		lv = distance(xx.begin(), lower_bound(xx.begin(), xx.end(), x0+1));
		rv = distance(xx.begin(), upper_bound(xx.begin(), xx.end(), x1-1));
		ans += getans(0, sz, lv, rv, 0, x0, x1);
		cout << n - ans << endl;
	}

	return 0;
}

// Sat Jan 28 2017 16:23:11 GMT+0300 (MSK)


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
#define S(v) sort(v.begin(),v.end());
#define A(v) v.begin(),v.end()
const int maxl = (1e6) + 3;

void unite(vector<int>& a) {
	S(a);
	vector<int> g;
	for (int h : a) {
		if (!g.size() || g[g.size() - 1] != h) g.push_back(h);
	}
	a = g;
}

struct stree {
	vector<vector<int>> tree;
	int n;
	stree(int g) {
		n = 1;
		while (g > n) {
			n <<= 1;
		}
		tree.resize(n << 1);
	}
	void put(int i, int j) {
		for (i += n; i > 0; i /= 2) {
			tree[i].push_back(j);
		}
	}
	int found(int x1, int x2, int y1, int y2) {
		int ans = 0;
		x1 += n, x2 += n;
		for (; x1 <= x2; x1 /= 2, x2 /= 2) {
			if (x1 % 2 == 1) {
				int g = upper_bound(A(tree[x1]),y2) - tree[x1].begin();
				g -= lower_bound(A(tree[x1]), y1) - tree[x1].begin();
				ans += g;
				x1++;
			}
			if (x2 % 2 == 0) {
				int g = upper_bound(A(tree[x2]), y2) - tree[x2].begin();
				g -= lower_bound(A(tree[x2]), y1) - tree[x2].begin();
				ans += g;
				x2--;
			}
		}
		return ans;
	}
	void sortall() {
		for (vector<int>& a : tree) S(a);
	}
};

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n1, m,n;
	scanf("%d%d", &n1, &m);
	vector<pair<int, int>> otr;
	vector<int> nach;
	for (int i = 0; i < n1; ++i) {
		int l, r;
		scanf("%d%d", &l, &r);
		nach.push_back(l);
		nach.push_back(r);
		otr.push_back(make_pair(l, r));
	}
	unite(nach);
	stree rr(nach.size() + 2);
	for (pair<int, int> para : otr) {
		rr.put(lower_bound(A(nach),para.first)-nach.begin(), para.second);
	}
	rr.sortall();
	for (int i = 0; i < m; ++i) {
		cin >> n;
		int p1 = -1, p2 = 0;
		int ans = 0;
		for (int i = 0; i <= n; ++i) {
			if (i == n) p2 = maxl;
			else scanf("%d",&p2);
			int x1, x2;
			x2 = lower_bound(nach.begin(), nach.end(), p2) - nach.begin();
			x2--;
			x1 = upper_bound(nach.begin(), nach.end(), p1) - nach.begin();
			ans += rr.found(x1,x2,p1+1, p2-1);
			p1 = p2;
		}
		printf("%d\n", n1 - ans);
	}
}

// Sat Jan 28 2017 21:51:32 GMT+0300 (MSK)


#include <iostream>
#include <iomanip>
#include <cctype>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <queue>
#include <iterator>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <stack>
#include <fstream>
#include <bitset>
#include <unordered_map>

using namespace std;

#define Mfor(i,b,e) for(int  i=b; i<e; ++i)
#define Mrof(i,b,e) for(int i=e; i>=b; --i)
#define all(x) (x).begin(), (x).end()

vector<vector<int > > tr;
int sz = 1;
void bild(vector<int> &a) {
	while (a.size() > sz)sz *= 2;
	tr.resize(sz * 2);
	for (int i = 0; i < a.size(); i++) {
		tr[i + sz] = { a[i] };
	}
	for (int i = sz - 1; i > 0; i--) {
		tr[i].resize(tr[i * 2].size() + tr[i * 2 + 1].size());
		merge(all(tr[i * 2]), all(tr[i * 2 + 1]), tr[i].begin());
	}
}
/*void apd(int p, int cost) {
p += sz;
tr[p] = cost;
for (; p > 0; p /= 2) {
tr[p/2]=gcd(tr[p],tr[p ^ 1]);
}
}*/
inline int get(int l, int r, int y) {
	int res = 0;
	for (r += sz, l += sz; l <= r; l /= 2, r /= 2) {
		if (l & 1) {
			//int q = upper_bound(all(tr[l]), 1000000001) - tr[l].begin();
			//int z = lower_bound(all(tr[l]), y) - tr[l].begin();
			res += upper_bound(all(tr[l]), 1000000001) - lower_bound(all(tr[l]), y);
			l++;
		}

		if (!(r & 1)) {
			//int q = upper_bound(all(tr[r]), 1000000001) - tr[r].begin();
			//int z = lower_bound(all(tr[r]), y) - tr[r].begin();
			res += upper_bound(all(tr[r]), 1000000001) - lower_bound(all(tr[r]), y);
			r--;
		}
	}
	return res;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n;
	cin >> m;
	vector<pair<int, int> > tmp(n);
	for (int i = 0; i < n; i++) {
		cin >> tmp[i].first >> tmp[i].second;
	}
	vector<pair<int, int> > vals = tmp;
	sort(all(vals));
	for (pair<int, int> &x : tmp) {
		x.first = lower_bound(all(vals), x) - vals.begin();
	}
	vector<int>a(n, -1000000001);
	vector<int>c(n);
	for (int i = 0; i < n; i++) {
		while (a[tmp[i].first + c[tmp[i].first]] != -1000000001)c[tmp[i].first]++;
			a[tmp[i].first+ c[tmp[i].first]] = tmp[i].second;
	}
	bild(a);
	for (int i = 0; i < m; i++) {
		int k;
		cin >> k;
		int l = 0,r,x,y,ans=0;
		for (int j = 0; j < k; j++) {
			cin >> x;
			r = upper_bound(all(vals), make_pair(x, 1000000001)) - vals.begin() - 1;
			if (l <= r) {
				ans += get(l, r, x);
				l = r+1;
			}
		}
		cout << ans << endl;
	}
}

/* Sun Jan 27 2019 19:35:56 GMT+0300 (MSK) */


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>

using namespace std;

const int INF = 1000000000;
const int edge = 1000001;
vector<pair<int, int> > a;

struct segtree
{
    int n;
    vector<vector<int> > t;
    void build(const vector<pair<int,int> >& a) {
        n = 1;
        while (n < a.size()+1) {
            n += n;
        }
        t.resize(n + n);
        for (int i = 0; i < a.size(); ++i) {
            t[n + i].push_back(a[i].second);
        }
        for (int i = n - 1; i > 0; --i) {
            t[i].resize(t[2 * i].size() + t[2 * i + 1].size());
            merge(t[2 * i].begin(), t[2 * i].end(), t[2 * i + 1].begin(), t[2 * i + 1].end(), t[i].begin());
        }
    }
    void setsize(int sizeofthis) {
        n = 1;
        while (n < sizeofthis) {
            n += n;
        }
        t.resize(2*n);
    }
    void set(int i, int x) {
        i += n;
        t[i].push_back(x);
        while (i > 1) {
            i /= 2;
            t[i].push_back(x);
        }
    }
    int get_val(int l, int r, int y2, int y1) {
        int ans = 0;
        for (l += n, r += n; l <= r; l /= 2, r /= 2) {
            if (l %2==1) {
                ans += (upper_bound(t[l].begin(), t[l].end(), y2) - lower_bound(t[l].begin(), t[l].end(), y1));
                l++;
            }
            if (r % 2==0) {
                ans+= (upper_bound(t[r].begin(), t[r].end(), y2) - lower_bound(t[r].begin(), t[r].end(), y1));
                r--;
            }
        }
        return ans;
    }
};

int main()
{
 //   freopen("input.txt", "r", stdin);
 //   freopen("output.txt", "w", stdout);
    int n, m;
    cin >> n >> m;
    a.resize(n);
    set<pair<int, int> > pt;
    vector<int> xs;
    set<int> xsset;
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        pt.insert(make_pair(x, y));
        xsset.insert(x);
    }
    //sort(a.begin(), a.end());
    segtree s;
    s.setsize(n + 1);
    for (auto it = xsset.begin(); it != xsset.end(); it++) {
        xs.push_back(*it);
    }
    for (auto it = pt.begin(); it != pt.end(); it++) {
        int pos = (lower_bound(xs.begin(), xs.end(), it->first)-xs.begin());
        s.set(pos, it->second);
    }
    for (int i = 0; i < s.t.size(); ++i) {
        sort(s.t[i].begin(), s.t[i].end());
    }
    for (int i = 0; i < m; ++i) {
        int kol;
        cin >> kol;
        vector<int> pts(kol);
        for (int j = 0; j < kol; ++j) {
            cin >> pts[j];
        }
        int prev = 1;
        int ans = 0;
        for (int j = 0; j < kol; ++j) {
            if (pts[j] - 1 < prev) {
                prev = pts[j]+1;
                continue;
            }
            int it1 = (lower_bound(xs.begin(), xs.end(), prev) - xs.begin());
            int it2 = (upper_bound(xs.begin(), xs.end(), pts[j]-1) - xs.begin());
            it2--;
            ans += s.get_val(it1, it2, pts[j]-1, prev);
            prev = pts[j]+1;
        }
        if (prev <= edge) {
            int it1 = (lower_bound(xs.begin(), xs.end(), prev) - xs.begin());
            int it2 = (upper_bound(xs.begin(), xs.end(), edge-1) - xs.begin());
            it2--;
            ans += s.get_val(it1, it2, edge-1, prev);
        }
        cout << n - ans << '\n';
    }
}

// Sat Jan 28 2017 18:45:53 GMT+0300 (MSK)


#pragma comment(linker,"/STACK:128000000")
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>
#include <ctime>
#include <deque>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <tuple>
#include <iostream>
#include <random>
#include <list>
#include <iomanip>
#include <assert.h>
#include <random>
#include <complex>
#include <deque>
#include <iterator>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<double, double> ptd;

const int inf = (int)1e9 + 1000;
const ll infLL = 10000000000000001LL;
const int mod = (int)1e9 + 7;
const double eps = 1e-7;
const double pi = 3.141592653589793;
const int maxlen = (int)1e5 + 10;
const int base = (int)1e9;

const int dd = (int)300 + 10;

#define ACCEPTED return 0;
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define optimize cin.sync_with_stdio(false);cout.sync_with_stdio(false);cin.tie(0);
#define name "stars"

struct segm
{
    int l, r, i;

    bool operator < (segm s) const
    {
        return l < s.l || (l == s.l && r < s.r);
    }
};

vi R;
vi L;
vi t[4*maxlen];
int Q[maxlen];
segm S[maxlen];

int N;
void getN(int n)
{
    N = 1;
    while (N < n)
        N <<= 1;
}

void build(int tl = 0, int tr = N - 1, int v = 1)
{
    if (tl == tr) {
        if (tl < R.size())
            t[v] = {R[tl]};
    } else {
        int tm = (tl + tr) / 2;

        build(tl, tm, 2*v);
        build(tm + 1, tr, 2*v + 1);

        merge(all(t[2*v]), all(t[2*v + 1]), back_inserter(t[v]));
    }
}

int get(int ql, int qr, int x, int tl = 0, int tr = N - 1, int v = 1)
{
    if (ql <= tl && tr <= qr)
        return t[v].end() - lower_bound(all(t[v]), x);

    int tm = (tl + tr) / 2;

    int ans = 0;
    if (ql <= tm)
        ans += get(ql, qr, x,     tl, tm, 2*v);
    if (tm < qr)
        ans += get(ql, qr, x, tm + 1, tr, 2*v + 1);

    return ans;
}

int main()
{
#ifdef _DEBUG
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#else
    freopen(name".in", "rt", stdin);
    freopen(name".out", "wt", stdout);
#endif

    int n, m;
    scanf("%d %d", &n, &m);

    for (int i = 0; i < n; i++) {
        scanf("%d %d", &S[i].l, &S[i].r);
        S[i].i = i;
    }

    sort(S, S + n);

    for (int i = 0; i < n; i++) {
        R.push_back(S[i].r);
        L.push_back(S[i].l);
    }

    getN(R.size());
    build();

    while (m --> 0) {
        int k;
        scanf("%d", &k);

        int ans = 0;

        int a = 0;
        for (int i = 0; i < k; i++) {
            int b;
            scanf("%d", &b);

            int l = upper_bound(all(L), a) - L.begin();
            int r = upper_bound(all(L), b) - L.begin();

            r--;

            if (l <= r)
                ans += get(l, r, b);
            a = b;
        }

        printf("%d\n", ans);
    }

    return 0;
}
/* Sun Jan 27 2019 19:30:59 GMT+0300 (MSK) */


#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

// struct custom_hash {
//     static uint64_t splitmix64(uint64_t x) {
//         // http://xorshift.di.unimi.it/splitmix64.c
//         x += 0x9e3779b97f4a7c15;
//         x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//         x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//         return x ^ (x >> 31);
//     }

//     size_t operator()(uint64_t x) const {
//         static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
//         return splitmix64(x + FIXED_RANDOM);
//     }
// };

#define n_l '\n'
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); }
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl

#define REP(i,b) for(int i=0;i<(b);i++)
#define REPP(i,b) for(int i=1;i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>(b);i++)
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define MS(s) memset(s, 0, sizeof(s))
#define PB push_back
#define MP make_pair

typedef vector<pair<int, int>> VPII;
typedef pair<int, int> PII;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = (int) 1e9 + 7;
string ascii_lowercase = "abcdefghijklmnopqrstuvwxyz";
string ascii_uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

struct hashLL { /* mp.rehash(n << 2); */
    size_t operator()(ll x) const {
        x = (x ^ (x >> 30)) * UINT64_C(0xbf58476d1ce4e5b9);
        x = (x ^ (x >> 27)) * UINT64_C(0x94d049bb133111eb);
        x = x ^ (x >> 31);
        return x;
    }
};

long long inv(long long a, long long b) {
    return 1 < a ? b - inv(b % a, a) * b / a : 1;
}

const ll INF = 1e6;

// unordered_map<int, int, custom_hash> mp;
// unordered_map<int, unordered_map<int, int, custom_hash>, custom_hash> g;

ll gcd(ll a, ll b, ll &x, ll &y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    ll x1, y1;
    ll d = gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

ll distsq(ll x1, ll y1, ll x2, ll y2) {
    return (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
}

const int N = 5001;
ll n, m, k;
ll arr[N];
unordered_set<ll> bb;
vector<ll> primes;
const ll maxp = 34000;
bool aprimes[maxp];
int main() {
    // freopen("input.txt", "r", stdin); freopen("output.txt","w",stdout);
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m;
    REP(i,n) { cin >> arr[i]; }
    REP(i,m) { cin >> k; bb.insert(k); }
    for (int i = 2; i < maxp; i++) {
        if (aprimes[i]) {
            primes.PB(i);
            for (int j = i * i; j < maxp; j+=i) {
                aprimes[j]=false;
            }
        }
    }
    ll bestdiff = 0;
    ll tot = 0;
    ll d = arr[0];
    vector<ll> diffs;
    REP(i,n) {
        d = __gcd(d, arr[i]);
        ll currd = d;
        ll currdiff = 0;
        ll curr = arr[i];
        for (auto p : primes) {
            bool isbad = bb.count(p);
            while (curr%p==0) {
                curr/=p;
                if (isbad) tot--;
                else tot++;
            }
            while(currd%p==0) {
                currd/=p;
                if (isbad)currdiff++;
                else currdiff--;
            }
        }
        if (curr != 1) {
            if (bb.count(curr)) tot--;
            else tot++;
        }
        if (currd != 1) {
            if (bb.count(currd)) currdiff++;
            else currdiff--;
        }
        // dbg(d);
        diffs.PB(currdiff);
    }
    // dbg(diffs);
    ll currtotdiff = 0;
    for (int i = n - 1; i >= 0; i--) {
        ll currdiff = diffs[i];
        if (n==193 && m == 1)
            dbgm(i, tot, currdiff, currtotdiff, *bb.begin());
        if (currdiff - currtotdiff > 0) {
            tot += (currdiff-currtotdiff) * (i + 1);
            currtotdiff += currdiff;
        }
    }
    cout << tot;

    return 0;
}