#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

struct Counter
{
	static int k;
	Counter() {k++;}
	~Counter() {k--;}
};

int Counter::k = 0;

template<typename T>
void pr(const string& name, T t)
{
    cout << name << " = " << t << endl;
}

template<typename T, typename ... Types>
void pr(const string& names, T t, Types ... rest)
{
    auto comma_pos = names.find(',');
    cout << names.substr(0, comma_pos) << " = " << t << ", ";

    auto next_name_pos = names.find_first_not_of(" \t\n", comma_pos + 1);
    pr(string(names, next_name_pos), rest ...);
}

void mod(ll &a, ll b)
{
    a %= b;
    if(a < 0) a += b;
}

#define all(x) x.begin(), x.end()
#define f(i,a,b) for(int i = (a); i <= (b); i++)
#define fd(i,a,b) for(int i = (a); i >= (b); i--)
#define mp make_pair
#define faster_io() ios_base::sync_with_stdio(false)
#define pb push_back
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
#define trace(...) pr(#__VA_ARGS__, __VA_ARGS__);
#define tracea(x) {string s = #x; Counter c##x; cout<<s.substr(0,1+s.find('['))<<Counter::k<<"]="<<x<<'\n';}
#define vii vector<pair<int,int>>

const ll MOD = 1000000007;

// ----------------------------------------------------------------------------------------------------------

struct Event
{
    int type, x, v, id;
    Event(int p1, int p2, int p3, int p4) : type(p1), x(p2), v(p3), id(p4) {};
    friend bool operator < (Event e1, Event e2)
    {
        if(e1.x != e2.x) return e1.x < e2.x;
        return e1.type < e2.type;
    }
};

enum {SEG,QUERY};
int Ans[300005], N, Q, T[1000005];
multiset<Event> Events;

void update(int x)
{
    while(x > 0)
    {
        T[x]++;
        x -= x&-x;
    }
}

int query(int x)
{
    int ret = 0;
    while(x <= 1000000)
    {
        ret += T[x];
        x += x&-x;
    }
    return ret;
}

int main()
{
    cin >> N >> Q;
    f(i,1,N)
    {
        int l,r;
        cin >> l >> r;
        Events.insert(Event(SEG,r,l,0));
    }
    f(q,1,Q)
    {
        int cnt;
        cin >> cnt;
        int l = 0;
        f(i,1,cnt)
        {
            int x;
            cin >> x;
            Events.insert(Event(QUERY,x-1,l+1,q));
            l = x;
        }
        Events.insert(Event(QUERY,1000000,l+1,q));
    }

    for(Event e : Events)
    {
        if(e.type == SEG) update(e.v);
        else Ans[e.id] += query(e.v);
    }

    f(i,1,Q) cout << N - Ans[i] << "\n";
}


#include<bits/stdc++.h>

using namespace std;

int const N = 3e5+10, max_val = 1e6+10;

int n, m;

int bit[2][max_val];

void update(int idx, int id){
	while(idx < max_val) bit[id][idx]++, idx += (idx & -idx);
}

int query(int idx, int id){
	int ret = 0;
	while(idx > 0) ret += bit[id][idx], idx -= (idx & -idx);
	return ret;
}

int main(){

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

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

		for(int k = 0; k < m; k++){
			int sz, ans = 0, last = 0;
			scanf(" %d", &sz);
			for(int i = 0; i < sz; i++){
				int p;
				scanf(" %d", &p);
				int R = query(p-1,1);
				if(!last) ans += R;
				else{
					int L = query(last,0);
					ans += max(0,((R - ans) - (L - ans)));
				}
				last = p;
			}
			ans += (query(last+1,0)-query(last,0));
			printf("%d\n", n - ans);
		}

		return 0;

}


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

int const N = 3e5 + 10;
int const MAXP = 1e6;

int n, m;

struct line
{
	int x, type, id, pos;
	bool last;

	line (int x, int type, int id, int pos, bool last) : x(x), type(type), id(id), pos(pos), last(last) {}
};

bool operator < (line A, line B)
{
	return (A.x < B.x) || (A.x == B.x && A.type > B.type);
}

vector <line> L;
int ans[N], pre[MAXP];

int BIT[MAXP];

void update (int idx)
{
	while (idx < MAXP)
	{
		BIT[idx]++;
		idx += (idx & -idx);
	}
}

int get (int idx)
{
	int sum = 0;

	while (idx > 0)
	{
		sum += BIT[idx];
		idx -= (idx & -idx);
	}

	return sum;
}

void solve ()
{
	sort (L.begin(), L.end());

	for (int i = 0; i < L.size(); i++)
	{
		int x = L[i].x;
		int type = L[i].type;
		int id = L[i].id;
		int pos = L[i].pos;
		bool last = L[i].last;

		if (!type)
			update (pos);
		else
		{
			ans[id] -= (get(x) - get(pos));

			if (last)
				ans[id] -= pre[x + 1];
		}
	}
}

int main ()
{
	cin.sync_with_stdio (false);
	cin.tie (0);
	cout.tie (0);

	cin >> n >> m;

	for (int i = 0; i < n; i++)
	{
		int l, r;
		cin >> l >> r;

		L.push_back (line (r, 0, -1, l, 0));
		pre[l]++;
	}

	for (int i = MAXP; i >= 1; i--)
		pre[i] += pre[i + 1];

	for (int i = 0; i < m; i++)
	{
		ans[i] = n;
		int cnt;
		cin >> cnt;

		int last = -1;

		for (int j = 0; j < cnt; j++)
		{
			int p;
			cin >> p;

			bool flag = (j == (cnt - 1)) ? (true) : (false);

			if (!j)
				L.push_back (line (p, 1, i, 0, flag));
			else
				L.push_back (line (p, 1, i, last, flag));

			last = p;
		}
	}

	solve();

	for (int i = 0; i < m; i++)
		cout << ans[i] << '\n';

	return 0;
}


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

int const N = 3e5 + 10;
int const MAXP = 1e6;

int n, m;

struct line
{
	int x, type, id, pos;
	bool last;

	line (int x, int type, int id, int pos, bool last) : x(x), type(type), id(id), pos(pos), last(last) {}
};

bool operator < (line A, line B)
{
	return (A.x < B.x) || (A.x == B.x && A.type > B.type);
}

vector <line> L;
int ans[N], pre[MAXP + 10];

int BIT[MAXP + 10];

void update (int idx)
{
	while (idx < MAXP)
	{
		BIT[idx]++;
		idx += (idx & -idx);
	}
}

int get (int idx)
{
	int sum = 0;

	while (idx > 0)
	{
		sum += BIT[idx];
		idx -= (idx & -idx);
	}

	return sum;
}

void solve ()
{
	sort (L.begin(), L.end());

	for (int i = 0; i < L.size(); i++)
	{
		int x = L[i].x;
		int type = L[i].type;
		int id = L[i].id;
		int pos = L[i].pos;
		bool last = L[i].last;

		if (!type)
			update (pos);
		else
		{
			ans[id] -= (get(x) - get(pos));

			if (last)
				ans[id] -= pre[x + 1];
		}
	}
}

int main ()
{
	cin.sync_with_stdio (false);
	cin.tie (0);
	cout.tie (0);

	cin >> n >> m;

	for (int i = 0; i < n; i++)
	{
		int l, r;
		cin >> l >> r;

		L.push_back (line (r, 0, -1, l, 0));
		pre[l]++;
	}

	for (int i = MAXP; i >= 1; i--)
		pre[i] += pre[i + 1];

	for (int i = 0; i < m; i++)
	{
		ans[i] = n;

		int cnt;
		cin >> cnt;

		int last = -1;

		for (int j = 0; j < cnt; j++)
		{
			int p;
			cin >> p;

			bool flag = (j == (cnt - 1)) ? (true) : (false);

			if (!j)
				L.push_back (line (p, 1, i, 0, flag));
			else
				L.push_back (line (p, 1, i, last, flag));

			last = p;
		}
	}

	solve();

	for (int i = 0; i < m; i++)
		cout << ans[i] << '\n';

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int const N = 3e5+10, max_val = 1e6+10;

int n, m;

int bit[2][max_val];

void update(int idx, int id){
	while(idx < max_val) bit[id][idx]++, idx += (idx & -idx);
}

int query(int idx, int id){
	int ret = 0;
	while(idx > 0) ret += bit[id][idx], idx -= (idx & -idx);
	return ret;
}

int main(){

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

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

		for(int k = 0; k < m; k++){
			int sz, ans = 0, last = 0;
			scanf(" %d", &sz);
			for(int i = 0; i < sz; i++){
				int p;
				scanf(" %d", &p);
				int R = query(p-1,1);
				if(!last) ans += R;
				else{
					int L = query(last,0);
					ans += max(0,((R - ans) - (L - ans)));
				}
				last = p;
			}
			ans += (query(max_val-1,0)-query(last,0));
			printf("%d\n", n - ans);
		}

		return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
const int NMax = 300005;
int N, M;
pair <int, int> Array[NMax];
vector <int> V[NMax];
vector <pair <int, int> > P[1000005];
int Number[1000005], ind;
bool Exist[1000005];
int Res[NMax];
int Aib[1000005];
int Partial[1000005];
int A[NMax];
void Update(int poz)
{
    int i=poz;
    while(i>=1)
    {
        Aib[i]++;
        i -= i&(-i);
    }
}
int Sum(int poz)
{
    int ans = 0, i=poz;
    while(i<=1000000)
    {
        ans += Aib[i];
        i += i&(-i);
    }
    return ans;
}
void Read()
{
    cin >> N >> M;
    for(int i = 1; i <= N; i++)
    {
        cin >> Array[i].first >> Array[i].second;
    }
    sort(Array + 1, Array + N + 1);
    for(int i = 1; i <= M; i++)
    {
        int cnt;
        cin >> cnt;
        for(int j = 1; j <= cnt; j++)
        {
            int val;
            cin >> val;
            if(Exist[val] == 0)
                A[++A[0]]=val;
            Exist[val] = 1;
            V[i].push_back(val);
        }
        sort(V[i].begin(), V[i].end());
        for(int j = 0; j < V[i].size() - 1; j++)
            P[V[i][j]].push_back(make_pair(V[i][j + 1], i));
    }
    sort(A + 1,A+A[0]+1);
}

/*void buildNumber()
{
    int nb = 0;
    sort(E + 1, E + ind + 1);
    for(int i = 1; i <= ind; i++)
    {
        if(E[i].second == 0)
            ++nb;
        if(E[i].second == 1)
            --nb;
        if(E[i].second == 2)
            Number[E[i].first]=nb;
    }
}*/
void Solve()
{
    int poz = 1;
    for(int i = 1; i <= N; i++)
    {
        while(poz<=A[0] && A[poz]<Array[i].first)
        {
            Number[A[poz]] = Sum(A[poz]);
            for(int j = 0; j < P[A[poz]].size();j++)
            {
                int x = P[A[poz]][j].first,y = P[A[poz]][j].second;
                Res[y] -= Sum(x);
            }
            ++poz;
        }
        Update(Array[i].second);
        Partial[Array[i].second]++;
    }
    for(int i = 1000000; i>=1 ;i--)
        Partial[i] += Partial[i+1];
    while(poz<=A[0])
        {
            for(int j = 0; j < P[A[poz]].size();j++)
            {
                int x = P[A[poz]][j].first,y = P[A[poz]][j].second;
                Res[y] -= Partial[x];
            }
            ++poz;
        }
    for(int i = 1; i <= M; i++)
    {
        for(int j = 0; j < V[i].size(); j++)
        {
            Res[i]+=Number[V[i][j]];
        }
        printf("%d\n",Res[i]);
    }
}
int main()
{
    Read();
    //buildNumber();
    Solve();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
const int NMax = 300005;
int N, M;
pair <int, int> Array[NMax];
pair<int, int> E[1000005];
vector <int> V[NMax];
vector <pair <int, int> > P[1000005];
int Number[1000005], ind;
bool Exist[1000005];
int Res[NMax];
int Aib[1000005];
int Partial[1000005];
int A[NMax];
void Update(int poz)
{
    int i=poz;
    while(i>=1)
    {
        Aib[i]++;
        i -= i&(-i);
    }
}
int Sum(int poz)
{
    int ans = 0, i=poz;
    while(i<=1000000)
    {
        ans += Aib[i];
        i += i&(-i);
    }
    return ans;
}
void Read()
{
    cin >> N >> M;
    for(int i = 1; i <= N; i++)
    {
        cin >> Array[i].first >> Array[i].second;
        E[++ind].first = Array[i].first;
        E[ind].second = 0;
        E[++ind].first = Array[i].second+1;
        E[ind].second = 1;
    }
    sort(Array + 1, Array + N + 1);
    for(int i = 1; i <= M; i++)
    {
        int cnt;
        cin >> cnt;
        for(int j = 1; j <= cnt; j++)
        {
            int val;
            cin >> val;
            if(Exist[val] == 0)
                E[++ind].first = val, E[ind].second = 2,A[++A[0]]=val;
            Exist[val] = 1;
            V[i].push_back(val);
        }
        sort(V[i].begin(), V[i].end());
        for(int j = 0; j < V[i].size() - 1; j++)
            P[V[i][j]].push_back(make_pair(V[i][j + 1], i));
    }
    sort(A + 1,A+A[0]+1);
}

void buildNumber()
{
    int nb = 0;
    sort(E + 1, E + ind + 1);
    for(int i = 1; i <= ind; i++)
    {
        if(E[i].second == 0)
            ++nb;
        if(E[i].second == 1)
            --nb;
        if(E[i].second == 2)
            Number[E[i].first]=nb;
    }
}
void Solve()
{
    int poz = 1;
    for(int i = 1; i <= N; i++)
    {
        while(poz<=A[0] && A[poz]<Array[i].first)
        {
            for(int j = 0; j < P[A[poz]].size();j++)
            {
                int x = P[A[poz]][j].first,y = P[A[poz]][j].second;
                Res[y] -= Sum(x);
            }
            ++poz;
        }
        Update(Array[i].second);
        Partial[Array[i].second]++;
    }
    for(int i = 1000000; i>=1 ;i--)
        Partial[i] += Partial[i+1];
    while(poz<=A[0])
        {
            for(int j = 0; j < P[A[poz]].size();j++)
            {
                int x = P[A[poz]][j].first,y = P[A[poz]][j].second;
                Res[y] -= Partial[x];
            }
            ++poz;
        }
    for(int i = 1; i <= M; i++)
        for(int j = 0; j < V[i].size(); j++)
            Res[i]+=Number[V[i][j]];
    for(int i = 1; i <= M; i++)
        printf("%d\n",Res[i]);
}
int main()
{
    Read();
    buildNumber();
    Solve();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
const int NMax = 300005;
int N, M;
pair <int, int> Array[NMax];
vector <int> V[NMax];
pair<pair <int, int>, int> P[1000005];
int  ind, ind2;
bool Exist[1000005];
int Res[NMax];
int Aib[1000005];
int A[NMax];
void Update(int poz)
{
    int i=poz;
    while(i<=1000000)
    {
        Aib[i]++;
        i += i&(-i);
    }
}
int Sum(int poz)
{
    int ans = 0, i=poz;
    while(i>=1)
    {
        ans += Aib[i];
        i -= i&(-i);
    }
    return ans;
}
void Read()
{
    scanf("%d%d",&N,&M);
    for(int i = 1; i <= N; i++)
    {
        scanf("%d%d",&Array[i].first, &Array[i].second);
    }
    sort(Array + 1, Array + N + 1);
    for(int i = 1; i <= M; i++)
    {
        int cnt;
        scanf("%d",&cnt);
        for(int j = 1; j <= cnt; j++)
        {
            int val;
            scanf("%d",&val);
            if(Exist[val] == 0)
                A[++A[0]]=val;
            Exist[val] = 1;
            V[i].push_back(val);
        }
        V[i].push_back(0);
        V[i].push_back(1000001);
        sort(V[i].begin(), V[i].end());
        for(int j = 0; j < V[i].size() - 1; j++)
            P[++ind2]=make_pair(make_pair(V[i][j],V[i][j + 1]), i);
    }
    sort(A + 1,A+A[0]+1);
    sort(P + 1, P + ind2 + 1);
}

/*void buildNumber()
{
    int nb = 0;
    sort(E + 1, E + ind + 1);
    for(int i = 1; i <= ind; i++)
    {
        if(E[i].second == 0)
            ++nb;
        if(E[i].second == 1)
            --nb;
        if(E[i].second == 2)
            Number[E[i].first]=nb;
    }
}*/
void Solve()
{
    int poz = N;
    for(int i = ind2; i >= 1; i--)
    {
        while(poz>=1 && P[i].first.first<Array[poz].first)
        {
            Update(Array[poz].second);
            --poz;
        }
        Res[P[i].second] += Sum(P[i].first.second - 1);
    }
    for(int i = 1; i <= M; i++)
    {
        printf("%d\n",N - Res[i]);
    }
}
int main()
{
    Read();
    //buildNumber();
    Solve();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int NMax = 300005;
int N, M;
pair <int, int> Array[NMax];
pair<int, int> E[1000005];
vector <int> V[NMax];
vector <pair <int, int> > P[1000005];
int Number[1000005], ind;
bool Exist[1000005];
int Res[NMax];
int Aib[1000005];
int Partial[1000005];
void Update(int poz)
{
    int i=poz;
    while(i>=1)
    {
        Aib[i]++;
        i -= i&(-i);
    }
}
int Sum(int poz)
{
    int ans = 0, i=poz;
    while(i<=1000000)
    {
        ans += Aib[i];
        i += i&(-i);
    }
    return ans;
}
void Read()
{
    cin >> N >> M;
    for(int i = 1; i <= N; i++)
    {
        cin >> Array[i].first >> Array[i].second;
        E[++ind].first = Array[i].first;
        E[ind].second = 0;
        E[++ind].first = Array[i].second+1;
        E[ind].second = 1;
    }
    sort(Array + 1, Array + N + 1);
    for(int i = 1; i <= M; i++)
    {
        int cnt;
        cin >> cnt;
        for(int j = 1; j <= cnt; j++)
        {
            int val;
            cin >> val;
            if(Exist[val] == 0)
                E[++ind].first = val, E[ind].second = 2;
            Exist[val] = 1;
            V[i].push_back(val);
        }
        sort(V[i].begin(), V[i].end());
        for(int j = 0; j < V[i].size() - 1; j++)
            P[V[i][j]].push_back(make_pair(V[i][j + 1], i));
    }
}

void buildNumber()
{
    int nb = 0;
    sort(E + 1, E + ind + 1);
    for(int i = 1; i <= ind; i++)
    {
        if(E[i].second == 0)
            ++nb;
        if(E[i].second == 1)
            --nb;
        if(E[i].second == 2)
            Number[E[i].first]=nb;
    }
}
void Solve()
{
    int poz = 1;
    for(int i = 1; i <= N; i++)
    {
        while(poz<=ind && E[poz].first < Array[i].first)
        {
            if(E[poz].second==2)
            for(int j = 0; j < P[E[poz].first].size();j++)
            {
                int x = P[E[poz].first][j].first,y = P[E[poz].first][j].second;
                Res[y] -= Sum(x);
            }
            ++poz;
        }
        Update(Array[i].second);
        Partial[Array[i].second]++;
    }
    for(int i = 1000000; i>=1 ;i--)
        Partial[i] += Partial[i+1];
    while(poz<=ind)
        {
            if(E[poz].second==2)
            for(int j = 0; j < P[E[poz].first].size();j++)
            {
                int x = P[E[poz].first][j].first,y = P[E[poz].first][j].second;
                Res[y] -= Partial[x];
            }
            ++poz;
        }
    for(int i = 1; i <= M; i++)
        for(int j = 0; j < V[i].size(); j++)
            Res[i]+=Number[V[i][j]];
    for(int i = 1; i <= M; i++)
        cout << Res[i] << "\n";
}
int main()
{
    Read();
    buildNumber();
    Solve();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int NMax = 300005;
int N, M;
pair <int, int> Array[NMax];
struct event{
int p, ev;
} E[1000005];
vector <int> V[NMax];
vector <pair <int, int> > P[1000005];
int Number[1000005], ind;
bool Exist[1000005];
int Res[NMax];
int Aib[1000005];
void Update(int poz)
{
    int i=poz;
    while(i>=1)
    {
        Aib[i]++;
        i -= i&(-i);
    }
}
int Sum(int poz)
{
    int ans = 0, i=poz;
    while(i<=1000000)
    {
        ans += Aib[i];
        i += i&(-i);
    }
    return ans;
}
void Read()
{
    cin >> N >> M;
    for(int i = 1; i <= N; i++)
    {
        cin >> Array[i].first >> Array[i].second;
        E[++ind].p = Array[i].first;
        E[ind].ev = 0;
        E[++ind].p = Array[i].second+1;
        E[ind].ev = 1;
    }
    sort(Array + 1, Array + N + 1);
    for(int i = 1; i <= M; i++)
    {
        int cnt;
        cin >> cnt;
        for(int j = 1; j <= cnt; j++)
        {
            int val;
            cin >> val;
            if(Exist[val] == 0)
                E[++ind].p = val, E[ind].ev = 2;
            Exist[val] = 1;
            V[i].push_back(val);
        }
        sort(V[i].begin(), V[i].end());
        for(int j = 0; j < V[i].size() - 1; j++)
            P[V[i][j]].push_back(make_pair(V[i][j + 1], i));
    }
}
inline bool cmp(event a, event b)
{
    if(a.p == b.p)
        return a.ev<b.ev;
    return a.p < b.p;
}
void buildNumber()
{
    int nb = 0;
    sort(E + 1, E + ind + 1, cmp);
    for(int i = 1; i <= ind; i++)
    {
        if(E[i].ev == 0)
            ++nb;
        if(E[i].ev == 1)
            --nb;
        if(E[i].ev == 2)
            Number[E[i].p]=nb;
    }
}
void Solve()
{
    int poz = 1;
    for(int i = 1; i <= N; i++)
    {
        while(poz<=ind && E[poz].p < Array[i].first)
        {
            if(E[poz].ev==2)
            for(int j = 0; j < P[E[poz].p].size();j++)
            {
                int x = P[E[poz].p][j].first,y = P[E[poz].p][j].second;
                Res[y] -= Sum(x);
            }
            ++poz;
        }
        Update(Array[i].second);
    }
    while(poz<=ind)
        {
            if(E[poz].ev==2)
            for(int j = 0; j < P[E[poz].p].size();j++)
            {
                int x = P[E[poz].p][j].first,y = P[E[poz].p][j].second;
                Res[y] -= Sum(x);
            }
            ++poz;
        }
    for(int i = 1; i <= M; i++)
        for(int j = 0; j < V[i].size(); j++)
            Res[i]+=Number[V[i][j]];
    for(int i = 1; i <= M; i++)
        cout << Res[i] << "\n";
}
int main()
{
    Read();
    buildNumber();
    Solve();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
const int NMax = 300005;
int N, M;
pair <int, int> Array[NMax];
vector <int> V[NMax];
vector <pair <int, int> > P[1000005];
int Number[1000005], ind;
bool Exist[1000005];
int Res[NMax];
int Aib[1000005];
int Partial[1000005];
int A[NMax];
void Update(int poz)
{
    int i=poz;
    while(i>=1)
    {
        Aib[i]++;
        i -= i&(-i);
    }
}
int Sum(int poz)
{
    int ans = 0, i=poz;
    while(i<=1000000)
    {
        ans += Aib[i];
        i += i&(-i);
    }
    return ans;
}
void Read()
{
    cin >> N >> M;
    for(int i = 1; i <= N; i++)
    {
        cin >> Array[i].first >> Array[i].second;
        E[++ind].first = Array[i].first;
        E[ind].second = 0;
        E[++ind].first = Array[i].second+1;
        E[ind].second = 1;
    }
    sort(Array + 1, Array + N + 1);
    for(int i = 1; i <= M; i++)
    {
        int cnt;
        cin >> cnt;
        for(int j = 1; j <= cnt; j++)
        {
            int val;
            cin >> val;
            if(Exist[val] == 0)
                A[++A[0]]=val;
            Exist[val] = 1;
            V[i].push_back(val);
        }
        sort(V[i].begin(), V[i].end());
        for(int j = 0; j < V[i].size() - 1; j++)
            P[V[i][j]].push_back(make_pair(V[i][j + 1], i));
    }
    sort(A + 1,A+A[0]+1);
}

/*void buildNumber()
{
    int nb = 0;
    sort(E + 1, E + ind + 1);
    for(int i = 1; i <= ind; i++)
    {
        if(E[i].second == 0)
            ++nb;
        if(E[i].second == 1)
            --nb;
        if(E[i].second == 2)
            Number[E[i].first]=nb;
    }
}*/
void Solve()
{
    int poz = 1;
    for(int i = 1; i <= N; i++)
    {
        while(poz<=A[0] && A[poz]<Array[i].first)
        {
            Number[A[poz]] = Sum(A[poz]);
            for(int j = 0; j < P[A[poz]].size();j++)
            {
                int x = P[A[poz]][j].first,y = P[A[poz]][j].second;
                Res[y] -= Sum(x);
            }
            ++poz;
        }
        Update(Array[i].second);
        Partial[Array[i].second]++;
    }
    for(int i = 1000000; i>=1 ;i--)
        Partial[i] += Partial[i+1];
    while(poz<=A[0])
        {
            for(int j = 0; j < P[A[poz]].size();j++)
            {
                int x = P[A[poz]][j].first,y = P[A[poz]][j].second;
                Res[y] -= Partial[x];
            }
            ++poz;
        }
    for(int i = 1; i <= M; i++)
    {
        for(int j = 0; j < V[i].size(); j++)
        {
            Res[i]+=Number[V[i][j]];
        }
        printf("%d\n",Res[i]);
    }
}
int main()
{
    Read();
    //buildNumber();
    Solve();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
const int NMax = 300005;
int N, M;
pair <int, int> Array[NMax];
vector <int> V[NMax];
pair<pair <int, int>, int> P[1000005];
int Number[1000005], ind, ind2;
bool Exist[1000005];
int Res[NMax];
int Aib[1000005];
int Partial[1000005];
int A[NMax];
void Update(int poz)
{
    int i=poz;
    while(i<=1000000)
    {
        Aib[i]++;
        i += i&(-i);
    }
}
int Sum(int poz)
{
    int ans = 0, i=poz;
    while(i>=1)
    {
        ans += Aib[i];
        i -= i&(-i);
    }
    return ans;
}
void Read()
{
    cin >> N >> M;
    for(int i = 1; i <= N; i++)
    {
        cin >> Array[i].first >> Array[i].second;
    }
    sort(Array + 1, Array + N + 1);
    for(int i = 1; i <= M; i++)
    {
        int cnt;
        cin >> cnt;
        for(int j = 1; j <= cnt; j++)
        {
            int val;
            cin >> val;
            if(Exist[val] == 0)
                A[++A[0]]=val;
            Exist[val] = 1;
            V[i].push_back(val);
        }
        V[i].push_back(0);
        V[i].push_back(1000001);
        sort(V[i].begin(), V[i].end());
        for(int j = 0; j < V[i].size() - 1; j++)
            P[++ind2]=make_pair(make_pair(V[i][j],V[i][j + 1]), i);
    }
    sort(A + 1,A+A[0]+1);
    sort(P + 1, P + ind2 + 1);
}

/*void buildNumber()
{
    int nb = 0;
    sort(E + 1, E + ind + 1);
    for(int i = 1; i <= ind; i++)
    {
        if(E[i].second == 0)
            ++nb;
        if(E[i].second == 1)
            --nb;
        if(E[i].second == 2)
            Number[E[i].first]=nb;
    }
}*/
void Solve()
{
    int poz = N;
    for(int i = ind2; i >= 1; i--)
    {
        while(poz>=1 && P[i].first.first<Array[poz].first)
        {
            Update(Array[poz].second);
            --poz;
        }
        Res[P[i].second] += Sum(P[i].first.second - 1);
    }
    for(int i = 1; i <= M; i++)
    {
        printf("%d\n",N - Res[i]);
    }
}
int main()
{
    Read();
    //buildNumber();
    Solve();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
const int NMax = 300005;
int N, M;
pair <int, int> Array[NMax];
pair<int, int> E[1000005];
vector <int> V[NMax];
vector <pair <int, int> > P[1000005];
int Number[1000005], ind;
bool Exist[1000005];
int Res[NMax];
int Aib[1000005];
int Partial[1000005];
int A[NMax];
void Update(int poz)
{
    int i=poz;
    while(i>=1)
    {
        Aib[i]++;
        i -= i&(-i);
    }
}
int Sum(int poz)
{
    int ans = 0, i=poz;
    while(i<=1000000)
    {
        ans += Aib[i];
        i += i&(-i);
    }
    return ans;
}
void Read()
{
    cin >> N >> M;
    for(int i = 1; i <= N; i++)
    {
        cin >> Array[i].first >> Array[i].second;
        E[++ind].first = Array[i].first;
        E[ind].second = 0;
        E[++ind].first = Array[i].second+1;
        E[ind].second = 1;
    }
    sort(Array + 1, Array + N + 1);
    for(int i = 1; i <= M; i++)
    {
        int cnt;
        cin >> cnt;
        for(int j = 1; j <= cnt; j++)
        {
            int val;
            cin >> val;
            if(Exist[val] == 0)
                E[++ind].first = val, E[ind].second = 2,A[++A[0]]=val;
            Exist[val] = 1;
            V[i].push_back(val);
        }
        sort(V[i].begin(), V[i].end());
        for(int j = 0; j < V[i].size() - 1; j++)
            P[V[i][j]].push_back(make_pair(V[i][j + 1], i));
    }
    sort(A + 1,A+A[0]+1);
}

void buildNumber()
{
    int nb = 0;
    sort(E + 1, E + ind + 1);
    for(int i = 1; i <= ind; i++)
    {
        if(E[i].second == 0)
            ++nb;
        if(E[i].second == 1)
            --nb;
        if(E[i].second == 2)
            Number[E[i].first]=nb;
    }
}
void Solve()
{
    int poz = 1;
    for(int i = 1; i <= N; i++)
    {
        while(poz<=A[0] && A[poz]<Array[i].first)
        {
            for(int j = 0; j < P[A[poz]].size();j++)
            {
                int x = P[A[poz]][j].first,y = P[A[poz]][j].second;
                Res[y] -= Sum(x);
            }
            ++poz;
        }
        Update(Array[i].second);
        Partial[Array[i].second]++;
    }
    for(int i = 1000000; i>=1 ;i--)
        Partial[i] += Partial[i+1];
    while(poz<=A[0])
        {
            for(int j = 0; j < P[A[poz]].size();j++)
            {
                int x = P[A[poz]][j].first,y = P[A[poz]][j].second;
                Res[y] -= Partial[x];
            }
            ++poz;
        }
    for(int i = 1; i <= M; i++)
    {
        for(int j = 0; j < V[i].size(); j++)
        {
            Res[i]+=Number[V[i][j]];
        }
        printf("%d\n",Res[i]);
    }
}
int main()
{
    Read();
    buildNumber();
    Solve();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
const int NMax = 300005;
int N, M;
pair <int, int> Array[NMax];
pair<int, int> E[1000005];
vector <int> V[NMax];
vector <pair <int, int> > P[1000005];
int Number[1000005], ind;
bool Exist[1000005];
int Res[NMax];
int Aib[1000005];
int Partial[1000005];
void Update(int poz)
{
    int i=poz;
    while(i>=1)
    {
        Aib[i]++;
        i -= i&(-i);
    }
}
int Sum(int poz)
{
    int ans = 0, i=poz;
    while(i<=1000000)
    {
        ans += Aib[i];
        i += i&(-i);
    }
    return ans;
}
void Read()
{
    scanf("%d%d",&N,&M);
    for(int i = 1; i <= N; i++)
    {
        scanf("%d%d",&Array[i].first, &Array[i].second);
        E[++ind].first = Array[i].first;
        E[ind].second = 0;
        E[++ind].first = Array[i].second+1;
        E[ind].second = 1;
    }
    sort(Array + 1, Array + N + 1);
    for(int i = 1; i <= M; i++)
    {
        int cnt;
        scanf("%d",&cnt);
        for(int j = 1; j <= cnt; j++)
        {
            int val;
            scanf("%d",&val);
            if(Exist[val] == 0)
                E[++ind].first = val, E[ind].second = 2;
            Exist[val] = 1;
            V[i].push_back(val);
        }
        sort(V[i].begin(), V[i].end());
        for(int j = 0; j < V[i].size() - 1; j++)
            P[V[i][j]].push_back(make_pair(V[i][j + 1], i));
    }
}

void buildNumber()
{
    int nb = 0;
    sort(E + 1, E + ind + 1);
    for(int i = 1; i <= ind; i++)
    {
        if(E[i].second == 0)
            ++nb;
        if(E[i].second == 1)
            --nb;
        if(E[i].second == 2)
            Number[E[i].first]=nb;
    }
}
void Solve()
{
    int poz = 1;
    for(int i = 1; i <= N; i++)
    {
        while(poz<=ind && E[poz].first < Array[i].first)
        {
            if(E[poz].second==2)
            for(int j = 0; j < P[E[poz].first].size();j++)
            {
                int x = P[E[poz].first][j].first,y = P[E[poz].first][j].second;
                Res[y] -= Sum(x);
            }
            ++poz;
        }
        Update(Array[i].second);
        Partial[Array[i].second]++;
    }
    for(int i = 1000000; i>=1 ;i--)
        Partial[i] += Partial[i+1];
    while(poz<=ind)
        {
            if(E[poz].second==2)
            for(int j = 0; j < P[E[poz].first].size();j++)
            {
                int x = P[E[poz].first][j].first,y = P[E[poz].first][j].second;
                Res[y] -= Partial[x];
            }
            ++poz;
        }
    for(int i = 1; i <= M; i++)
        for(int j = 0; j < V[i].size(); j++)
            Res[i]+=Number[V[i][j]];
    for(int i = 1; i <= M; i++)
        printf("%d\n",Res[i]);
}
int main()
{
    Read();
    buildNumber();
    Solve();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
const int NMax = 300005;
int N, M;
pair <int, int> Array[NMax];
pair<int, int> E[1000005];
vector <int> V[NMax];
vector <pair <int, int> > P[1000005];
int Number[1000005], ind;
bool Exist[1000005];
int Res[NMax];
int Aib[1000005];
int Partial[1000005];
void Update(int poz)
{
    int i=poz;
    while(i>=1)
    {
        Aib[i]++;
        i -= i&(-i);
    }
}
int Sum(int poz)
{
    int ans = 0, i=poz;
    while(i<=1000000)
    {
        ans += Aib[i];
        i += i&(-i);
    }
    return ans;
}
void Read()
{
    cin >> N >> M;
    for(int i = 1; i <= N; i++)
    {
        cin >> Array[i].first >> Array[i].second;
        E[++ind].first = Array[i].first;
        E[ind].second = 0;
        E[++ind].first = Array[i].second+1;
        E[ind].second = 1;
    }
    sort(Array + 1, Array + N + 1);
    for(int i = 1; i <= M; i++)
    {
        int cnt;
        cin >> cnt;
        for(int j = 1; j <= cnt; j++)
        {
            int val;
            cin >> val;
            if(Exist[val] == 0)
                E[++ind].first = val, E[ind].second = 2;
            Exist[val] = 1;
            V[i].push_back(val);
        }
        sort(V[i].begin(), V[i].end());
        for(int j = 0; j < V[i].size() - 1; j++)
            P[V[i][j]].push_back(make_pair(V[i][j + 1], i));
    }
}

void buildNumber()
{
    int nb = 0;
    sort(E + 1, E + ind + 1);
    for(int i = 1; i <= ind; i++)
    {
        if(E[i].second == 0)
            ++nb;
        if(E[i].second == 1)
            --nb;
        if(E[i].second == 2)
            Number[E[i].first]=nb;
    }
}
void Solve()
{
    int poz = 1;
    for(int i = 1; i <= N; i++)
    {
        while(poz<=ind && E[poz].first < Array[i].first)
        {
            if(E[poz].second==2)
            for(int j = 0; j < P[E[poz].first].size();j++)
            {
                int x = P[E[poz].first][j].first,y = P[E[poz].first][j].second;
                Res[y] -= Sum(x);
            }
            ++poz;
        }
        Update(Array[i].second);
        Partial[Array[i].second]++;
    }
    for(int i = 1000000; i>=1 ;i--)
        Partial[i] += Partial[i+1];
    while(poz<=ind)
        {
            if(E[poz].second==2)
            for(int j = 0; j < P[E[poz].first].size();j++)
            {
                int x = P[E[poz].first][j].first,y = P[E[poz].first][j].second;
                Res[y] -= Partial[x];
            }
            ++poz;
        }
    for(int i = 1; i <= M; i++)
        for(int j = 0; j < V[i].size(); j++)
            Res[i]+=Number[V[i][j]];
    for(int i = 1; i <= M; i++)
        printf("%d\n",Res[i]);
}
int main()
{
    Read();
    buildNumber();
    Solve();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int NMax = 300005;
int N, M;
pair <int, int> Array[NMax];
pair<int, int> E[1000005];
vector <int> V[NMax];
vector <pair <int, int> > P[1000005];
int Number[1000005], ind;
bool Exist[1000005];
int Res[NMax];
int Aib[1000005];
void Update(int poz)
{
    int i=poz;
    while(i>=1)
    {
        Aib[i]++;
        i -= i&(-i);
    }
}
int Sum(int poz)
{
    int ans = 0, i=poz;
    while(i<=1000000)
    {
        ans += Aib[i];
        i += i&(-i);
    }
    return ans;
}
void Read()
{
    cin >> N >> M;
    for(int i = 1; i <= N; i++)
    {
        cin >> Array[i].first >> Array[i].second;
        E[++ind].first = Array[i].first;
        E[ind].second = 0;
        E[++ind].first = Array[i].second+1;
        E[ind].second = 1;
    }
    sort(Array + 1, Array + N + 1);
    for(int i = 1; i <= M; i++)
    {
        int cnt;
        cin >> cnt;
        for(int j = 1; j <= cnt; j++)
        {
            int val;
            cin >> val;
            if(Exist[val] == 0)
                E[++ind].first = val, E[ind].second = 2;
            Exist[val] = 1;
            V[i].push_back(val);
        }
        sort(V[i].begin(), V[i].end());
        for(int j = 0; j < V[i].size() - 1; j++)
            P[V[i][j]].push_back(make_pair(V[i][j + 1], i));
    }
}

void buildNumber()
{
    int nb = 0;
    sort(E + 1, E + ind + 1);
    for(int i = 1; i <= ind; i++)
    {
        if(E[i].second == 0)
            ++nb;
        if(E[i].second == 1)
            --nb;
        if(E[i].second == 2)
            Number[E[i].first]=nb;
    }
}
void Solve()
{
    int poz = 1;
    for(int i = 1; i <= N; i++)
    {
        while(poz<=ind && E[poz].first < Array[i].first)
        {
            if(E[poz].second==2)
            for(int j = 0; j < P[E[poz].first].size();j++)
            {
                int x = P[E[poz].first][j].first,y = P[E[poz].first][j].second;
                Res[y] -= Sum(x);
            }
            ++poz;
        }
        Update(Array[i].second);
    }
    while(poz<=ind)
        {
            if(E[poz].second==2)
            for(int j = 0; j < P[E[poz].first].size();j++)
            {
                int x = P[E[poz].first][j].first,y = P[E[poz].first][j].second;
                Res[y] -= Sum(x);
            }
            ++poz;
        }
    for(int i = 1; i <= M; i++)
        for(int j = 0; j < V[i].size(); j++)
            Res[i]+=Number[V[i][j]];
    for(int i = 1; i <= M; i++)
        cout << Res[i] << "\n";
}
int main()
{
    Read();
    buildNumber();
    Solve();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
const int NMax = 300005;
int N, M;
pair <int, int> Array[NMax];
vector <int> V[NMax];
pair<pair <int, int>, int> P[1000005];
int  ind, ind2;
bool Exist[1000005];
int Res[NMax];
int Aib[1000005];
int A[NMax];
void Update(int poz)
{
    int i=poz;
    while(i<=1000000)
    {
        Aib[i]++;
        i += i&(-i);
    }
}
int Sum(int poz)
{
    int ans = 0, i=poz;
    while(i>=1)
    {
        ans += Aib[i];
        i -= i&(-i);
    }
    return ans;
}
void Read()
{
    scanf("%d%d",&N,&M);
    for(int i = 1; i <= N; i++)
    {
        scanf("%d%d",&Array[i].first, &Array[i].second);
    }
    sort(Array + 1, Array + N + 1);
    for(int i = 1; i <= M; i++)
    {
        int cnt;
        scanf("%d",&cnt);
        V[i].push_back(0);
        for(int j = 1; j <= cnt; j++)
        {
            int val;
            scanf("%d",&val);
            if(Exist[val] == 0)
                A[++A[0]]=val;
            Exist[val] = 1;
            V[i].push_back(val);
        }
        V[i].push_back(1000001);
        for(int j = 0; j < V[i].size() - 1; j++)
            P[++ind2]=make_pair(make_pair(V[i][j],V[i][j + 1]), i);
    }
    sort(A + 1,A+A[0]+1);
    sort(P + 1, P + ind2 + 1);
}

/*void buildNumber()
{
    int nb = 0;
    sort(E + 1, E + ind + 1);
    for(int i = 1; i <= ind; i++)
    {
        if(E[i].second == 0)
            ++nb;
        if(E[i].second == 1)
            --nb;
        if(E[i].second == 2)
            Number[E[i].first]=nb;
    }
}*/
void Solve()
{
    int poz = N;
    for(int i = ind2; i >= 1; i--)
    {
        while(poz>=1 && P[i].first.first<Array[poz].first)
        {
            Update(Array[poz].second);
            --poz;
        }
        Res[P[i].second] += Sum(P[i].first.second - 1);
    }
    for(int i = 1; i <= M; i++)
    {
        printf("%d\n",N - Res[i]);
    }
}
int main()
{
    Read();
    //buildNumber();
    Solve();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
const int NMax = 300005;
int N, M;
pair <int, int> Array[NMax];
vector <int> V[NMax];
vector <pair <int, int> > P[1000005];
int Number[1000005], ind;
bool Exist[1000005];
int Res[NMax];
int Aib[1000005];
int Partial[1000005];
int A[NMax];
void Update(int poz)
{
    int i=poz;
    while(i>=1)
    {
        Aib[i]++;
        i -= i&(-i);
    }
}
int Sum(int poz)
{
    int ans = 0, i=poz;
    while(i<=1000000)
    {
        ans += Aib[i];
        i += i&(-i);
    }
    return ans;
}
void Read()
{
    cin >> N >> M;
    for(int i = 1; i <= N; i++)
    {
        cin >> Array[i].first >> Array[i].second;
    }
    sort(Array + 1, Array + N + 1);
    for(int i = 1; i <= M; i++)
    {
        int cnt;
        cin >> cnt;
        for(int j = 1; j <= cnt; j++)
        {
            int val;
            cin >> val;
            if(Exist[val] == 0)
                A[++A[0]]=val;
            Exist[val] = 1;
            V[i].push_back(val);
        }
        sort(V[i].begin(), V[i].end());
        for(int j = 0; j < V[i].size() - 1; j++)
            P[V[i][j]].push_back(make_pair(V[i][j + 1], i));
    }
    sort(A + 1,A+A[0]+1);
}

/*void buildNumber()
{
    int nb = 0;
    sort(E + 1, E + ind + 1);
    for(int i = 1; i <= ind; i++)
    {
        if(E[i].second == 0)
            ++nb;
        if(E[i].second == 1)
            --nb;
        if(E[i].second == 2)
            Number[E[i].first]=nb;
    }
}*/
void Solve()
{
    int poz = 1;
    for(int i = 1; i <= N; i++)
    {
        while(poz<=A[0] && A[poz]<Array[i].first)
        {
            Number[A[poz]] = Sum(A[poz]);
            for(int j = 0; j < P[A[poz]].size();j++)
            {
                int x = P[A[poz]][j].first,y = P[A[poz]][j].second;
                Res[y] -= Sum(x);
            }
            ++poz;
        }
        Update(Array[i].second);
        Partial[Array[i].second]++;
    }
    for(int i = 1000000; i>=1 ;i--)
        Partial[i] += Partial[i+1];
    while(poz<=A[0])
        {
            Number[A[poz]]=Partial[A[poz]];
            for(int j = 0; j < P[A[poz]].size();j++)
            {
                int x = P[A[poz]][j].first,y = P[A[poz]][j].second;
                Res[y] -= Partial[x];
            }
            ++poz;
        }
    for(int i = 1; i <= M; i++)
    {
        for(int j = 0; j < V[i].size(); j++)
        {
            Res[i]+=Number[V[i][j]];
        }
        printf("%d\n",Res[i]);
    }
}
int main()
{
    Read();
    //buildNumber();
    Solve();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int NMax = 300005;
int N, M;
pair <int, int> Array[NMax];
struct event{
int p, ev;
} E[1000005];
vector <int> V[NMax];
vector <pair <int, int> > P[1000005];
int Number[1000005], ind;
bool Exist[1000005];
int Res[NMax];
int Aib[1000005];
void Update(int poz)
{
    int i=poz;
    while(i>=1)
    {
        Aib[i]++;
        i -= i&(-i);
    }
}
int Sum(int poz)
{
    int ans = 0, i=poz;
    while(i<=1000000)
    {
        ans += Aib[i];
        i += i&(-i);
    }
    return ans;
}
void Read()
{
    cin >> N >> M;
    for(int i = 1; i <= N; i++)
    {
        cin >> Array[i].first >> Array[i].second;
        E[++ind].p = Array[i].first;
        E[ind].ev = 0;
        E[++ind].p = Array[i].second+1;
        E[ind].ev = 1;
    }
    sort(Array + 1, Array + N + 1);
    for(int i = 1; i <= M; i++)
    {
        int cnt;
        cin >> cnt;
        for(int j = 1; j <= cnt; j++)
        {
            int val;
            cin >> val;
            if(Exist[val] == 0)
                E[++ind].p = val, E[ind].ev = 2;
            Exist[val] = 1;
            V[i].push_back(val);
        }
        sort(V[i].begin(), V[i].end());
        for(int j = 0; j < V[i].size() - 1; j++)
            P[V[i][j]].push_back(make_pair(V[i][j + 1], i));
    }
}
inline bool cmp(event a, event b)
{
    if(a.p == b.p)
        return a.ev<b.ev;
    return a.p < b.p;
}
void buildNumber()
{
    int nb = 0;
    sort(E + 1, E + ind + 1, cmp);
    for(int i = 1; i <= ind; i++)
    {
        if(E[i].ev == 0)
            ++nb;
        if(E[i].ev == 1)
            --nb;
        if(E[i].ev == 2)
            Number[E[i].p]=nb;
    }
}
void Solve()
{
    int poz = 1;
    for(int i = 1; i <= N; i++)
    {
        while(poz<=ind && E[poz].p < Array[i].first)
        {
            if(E[poz].ev==2)
            for(int j = 0; j < P[E[poz].p].size();j++)
            {
                int x = P[E[poz].p][j].first,y = P[E[poz].p][j].second;
                Res[y] -= Sum(x);
            }
            ++poz;
        }
        Update(Array[i].second);
    }
    for(int i = 1; i <= M; i++)
        for(int j = 0; j < V[i].size(); j++)
            Res[i]+=Number[V[i][j]];
    for(int i = 1; i <= M; i++)
        cout << Res[i] << "\n";
}
int main()
{
    Read();
    buildNumber();
    Solve();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
const int NMax = 300005;
int N, M;
pair <int, int> Array[NMax];
pair<int, int> E[1000005];
vector <int> V[NMax];
vector <pair <int, int> > P[1000005];
int Number[1000005], ind;
bool Exist[1000005];
int Res[NMax];
int Aib[1000005];
int Partial[1000005];
int A[NMax];
void Update(int poz)
{
    int i=poz;
    while(i>=1)
    {
        Aib[i]++;
        i -= i&(-i);
    }
}
int Sum(int poz)
{
    int ans = 0, i=poz;
    while(i<=1000000)
    {
        ans += Aib[i];
        i += i&(-i);
    }
    return ans;
}
void Read()
{
    cin >> N >> M;
    for(int i = 1; i <= N; i++)
    {
        cin >> Array[i].first >> Array[i].second;
        E[++ind].first = Array[i].first;
        E[ind].second = 0;
        E[++ind].first = Array[i].second+1;
        E[ind].second = 1;
    }
    sort(Array + 1, Array + N + 1);
    for(int i = 1; i <= M; i++)
    {
        int cnt;
        cin >> cnt;
        for(int j = 1; j <= cnt; j++)
        {
            int val;
            cin >> val;
            if(Exist[val] == 0)
                E[++ind].first = val, E[ind].second = 2,A[++A[0]]=val;
            Exist[val] = 1;
            V[i].push_back(val);
        }
        sort(V[i].begin(), V[i].end());
        for(int j = 0; j < V[i].size() - 1; j++)
            P[V[i][j]].push_back(make_pair(V[i][j + 1], i));
    }
    sort(A + 1,A+A[0]+1);
}

void buildNumber()
{
    int nb = 0;
    sort(E + 1, E + ind + 1);
    for(int i = 1; i <= ind; i++)
    {
        if(E[i].second == 0)
            ++nb;
        if(E[i].second == 1)
            --nb;
        if(E[i].second == 2)
            Number[E[i].first]=nb;
    }
}
void Solve()
{
    int poz = 1;
    for(int i = 1; i <= N; i++)
    {
        while(poz<=A[0] && A[poz]<Array[i].first)
        {
            for(int j = 0; j < P[A[poz]].size();j++)
            {
                int x = P[A[poz]][j].first,y = P[A[poz]][j].second;
                Res[y] -= Sum(x);
            }
            ++poz;
        }
        Update(Array[i].second);
        Partial[Array[i].second]++;
    }
    for(int i = 1000000; i>=1 ;i--)
        Partial[i] += Partial[i+1];
    while(poz<=ind)
        {
            for(int j = 0; j < P[A[poz]].size();j++)
            {
                int x = P[A[poz]][j].first,y = P[A[poz]][j].second;
                Res[y] -= Partial[x];
            }
            ++poz;
        }
    for(int i = 1; i <= M; i++)
        for(int j = 0; j < V[i].size(); j++)
            Res[i]+=Number[V[i][j]];
    for(int i = 1; i <= M; i++)
        printf("%d\n",Res[i]);
}
int main()
{
    Read();
    buildNumber();
    Solve();
    return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define endl "\n"
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define fname ""
#define sz(x) (int)(x.size())
#define rep(i,x,y) for(long long i=x;i<=y;++i)
#define repr(i,x,y) for(long long i=x;i>=y;--i)

typedef long long ll;

using namespace std;

const ll N = (ll)(5e5) + 322;
const ll INF = (ll)(1e9);
const ll mod = (ll)(1e9) + 7;
const double eps = 1e-9;

int n, m, mxcnt, cnt, q, p[N], res, l, r;
vector <int> L, R;

int main () {
	ios_base :: sync_with_stdio (false); cin.tie(0);
	#ifdef lcl
		freopen(fname".in", "r", stdin);
		//freopen(fname".out", "w", stdout);
	#endif
	cin >> n >> m;
	rep(i, 1, n) {
		cin >> l >> r;
		L.pb(l); R.pb(r);
	}
	sort(all(L)); sort(all(R));
	rep(it, 1, m) {
		cin >> q;
		res = 0, mxcnt = 0, cnt = 0;
		rep(i, 1, q) cin >> p[i];
		sort(p + 1, p + q + 1);
		rep(i, 1, q) {
			l = --upper_bound(all(L), p[i]) - L.begin() + 1;
			r = --lower_bound(all(R), p[i]) - R.begin() + 1;
			r = max(r, mxcnt);
			res += (l - r);
			mxcnt = l;
		}
		cout << res << endl;
		memset(p, 0, sizeof p);
	}
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define endl "\n"
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define fname ""
#define sz(x) (int)(x.size())
#define rep(i,x,y) for(long long i=x;i<=y;++i)
#define repr(i,x,y) for(long long i=x;i>=y;--i)

typedef long long ll;

using namespace std;

const ll N = (ll)(5e5) + 322;
const ll INF = (ll)(1e9);
const ll mod = (ll)(1e9) + 7;
const double eps = 1e-9;

int n, m, mxcnt, cnt, q, p[N], res, l, r;
vector <int> L, R;

int main () {
	ios_base :: sync_with_stdio (false); cin.tie(0);
	#ifdef lcl
		freopen(fname".in", "r", stdin);
		//freopen(fname".out", "w", stdout);
	#endif
	cin >> n >> m;
	rep(i, 1, n) {
		cin >> l >> r;
		L.pb(l); R.pb(r);
	}
	sort(all(L)); sort(all(R));
	rep(it, 1, m) {
		cin >> q;
		res = 0, mxcnt = 0, cnt = 0;
		rep(i, 1, q) cin >> p[i];
		sort(p + 1, p + q + 1);
		rep(i, 1, q) {
			l = --upper_bound(all(L), p[i]) - L.begin() + 1;
			r = lower_bound(all(R), p[i]) - R.begin();
			r = max(r, mxcnt);
			res += (l - r);
			mxcnt = l;
		}
		cout << res << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define endl "\n"
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define fname ""
#define sz(x) (int)(x.size())
#define rep(i,x,y) for(long long i=x;i<=y;++i)
#define repr(i,x,y) for(long long i=x;i>=y;--i)

typedef long long ll;

using namespace std;

const ll N = (ll)(1e6) + 322;
const ll INF = (ll)(1e9);
const ll mod = (ll)(1e9) + 7;
const double eps = 1e-9;

int n, m, mxcnt, cnt, p[N], l, r, f[N], res[N];
vector <int> L[N];
vector <pair <int, int> > q[N];

inline void add(int i) {for (;i < N; i += (i & -i)) f[i]++;}

inline int get(int i) {int res = 0;for (;i >= 1; i -= (i & -i))res += f[i]; return res;}

inline int sum(int l, int r) {return get(r) - get(l - 1);}

int main () {
	ios_base :: sync_with_stdio (false); cin.tie(0);
	#ifdef lcl
		freopen(fname".in", "r", stdin);
		//freopen(fname".out", "w", stdout);
	#endif
	cin >> n >> m;
	rep(i, 1, n) {
		cin >> l >> r;
		L[r].pb(l);
	}
	rep(quer, 1, m) {
		cin >> cnt;
		p[1] = 0;
		p[cnt + 2] = N - 100;
		rep(i, 2, cnt + 1) cin >> p[i];
		sort(p + 1, p + cnt + 3);
		rep(i, 2, cnt + 2) {
			q[p[i]].pb(mp(p[i - 1], quer));
		}
	}
	rep(i, 1, N - 100) {
		for(auto it : q[i]) res[it.se] += sum(it.fi + 1, i - 1);
		for(auto it : L[i]) add(it);
	}
	rep(i, 1, m) cout << n - res[i] << endl;
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define endl "\n"
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define fname ""
#define sz(x) (int)(x.size())
#define rep(i,x,y) for(long long i=x;i<=y;++i)
#define repr(i,x,y) for(long long i=x;i>=y;--i)

typedef long long ll;

using namespace std;

const ll N = (ll)(1e6) + 322;
const ll INF = (ll)(1e9);
const ll mod = (ll)(1e9) + 7;
const double eps = 1e-9;

int n, m, mxcnt, cnt, p[N], l, r, f[N], res[N];
vector <int> L[N];
vector <pair <int, int> > q[N];
inline void add(int i) {for (;i < N; i += (i & -i)) f[i]++;}
inline int get(int i) {int res = 0;for (;i >= 1; i -= (i & -i))res += f[i]; return res;}
inline int sum(int l, int r) {return get(r) - get(l - 1);}
int main () {
	ios_base :: sync_with_stdio (false); cin.tie(0);
	#ifdef lcl
		freopen(fname".in", "r", stdin);
		//freopen(fname".out", "w", stdout);
	#endif
	cin >> n >> m;
	rep(i, 1, n) {cin >> l >> r;L[r].pb(l);}
	rep(quer, 1, m) {
		cin >> cnt;
		p[1] = 0;p[cnt + 2] = N - 100;
		rep(i, 2, cnt + 1) cin >> p[i];
		sort(p + 1, p + cnt + 3);
		rep(i, 2, cnt + 2) q[p[i]].pb(mp(p[i - 1], quer));
	}
	rep(i, 1, N - 100) {for(auto it : q[i]) res[it.se] += sum(it.fi + 1, i - 1);for(auto it : L[i]) add(it);}
	rep(i, 1, m) cout << n - res[i] << endl;
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define endl "\n"
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define fname ""
#define sz(x) (int)(x.size())
#define rep(i,x,y) for(long long i=x;i<=y;++i)
#define repr(i,x,y) for(long long i=x;i>=y;--i)

typedef long long ll;

using namespace std;

const ll N = (ll)(5e5) + 322;
const ll INF = (ll)(1e9);
const ll mod = (ll)(1e9) + 7;
const double eps = 1e-9;

int n, m, mxcnt, cnt, q, p[N], res, l, r;
vector <int> L, R;

int main () {
	ios_base :: sync_with_stdio (false); cin.tie(0);
	#ifdef lcl
		freopen(fname".in", "r", stdin);
		//freopen(fname".out", "w", stdout);
	#endif
	cin >> n >> m;
	rep(i, 1, n) {
		cin >> l >> r;
		L.pb(l); R.pb(r);
	}
	sort(all(L)); sort(all(R));
	rep(it, 1, m) {
		cin >> q;
		res = 0, mxcnt = 0, cnt = 0;
		rep(i, 1, q) cin >> p[i];
		sort(p + 1, p + q + 1);
		rep(i, 1, q) {
			l = --upper_bound(all(L), p[i]) - L.begin() + 1;
			r = --lower_bound(all(R), p[i]) - R.begin() + 1;
			r = max(r, mxcnt);
			res += (l - r);
			mxcnt = l;
		}
		cout << res << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define endl "\n"
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define fname ""
#define sz(x) (int)(x.size())
#define rep(i,x,y) for(long long i=x;i<=y;++i)
#define repr(i,x,y) for(long long i=x;i>=y;--i)

typedef long long ll;

using namespace std;

const ll N = (ll)(5e5) + 322;
const ll INF = (ll)(1e9);
const ll mod = (ll)(1e9) + 7;
const double eps = 1e-9;

int n, m, mxcnt, cnt, q, p[N], res, l, r;
vector <int> L, R;

int main () {
	ios_base :: sync_with_stdio (false); cin.tie(0);
	#ifdef lcl
		freopen(fname".in", "r", stdin);
		//freopen(fname".out", "w", stdout);
	#endif
	cin >> n >> m;
	rep(i, 1, n) {
		cin >> l >> r;
		L.pb(l); R.pb(r);
	}
	sort(all(L)); sort(all(R));
	rep(it, 1, m) {
		cin >> q;
		res = 0, mxcnt = 0, cnt = 0;
		rep(i, 1, q) cin >> p[i];
		sort(p + 1, p + q + 1);
		rep(i, 1, q) {
			l = upper_bound(all(L), p[i] - 1) - L.begin() + 1;
			r = lower_bound(all(R), p[i]) - R.begin();
			r = max(r, mxcnt);
			res += (l - r);
			mxcnt = l;
		}
		cout << res << endl;
	}
	return 0;
}


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

const int MAXN = 310000;

int n,m,cnt = 0;
struct Line{
  int l,r;
  bool operator < (const Line x)const{
    if(l != x.l) return l < x.l;
    else return r < x.r;//???有可能有问题
  }
}a[MAXN];

int t[MAXN];
map<int,int> S;

void init(){
  scanf("%d %d",&n,&m);
  for(int i = 1;i<=n;i++){
    scanf("%d %d",&a[i].l,&a[i].r);
    S[a[i].l] = 0;
  }
  sort(a+1,a+n+1);
  for(auto it = S.begin();it!=S.end();it++){
    it->second = ++cnt;
    t[cnt] = it->first;
  }
  for(int i = 1;i<=n;i++)
    a[i].l = S[a[i].l];
}

namespace SegTree{
  vector<int> v[MAXN<<2];
  #define lson (nown<<1)
  #define rson (nown<<1|1)
  #define mid ((l+r)>>1)
  void build(int nown,int l,int r,int *a){
    for(int i = l;i<=r;i++)
      v[nown].push_back(a[i]);
    sort(v[nown].begin(),v[nown].end());
    if(l == r) return;
    else
      build(lson,l,mid,a),build(rson,mid+1,r,a);
  }
  int a,b;
  void query(int nown,int l,int r,int ql,int qr,int &ans){
    if(ql <= l && r <= qr){
      ans += upper_bound(v[nown].begin(),v[nown].end(),b) - upper_bound(v[nown].begin(),v[nown].end(),a-1);
    }
    else{
      if(ql <= mid)
        query(lson,l,mid,ql,qr,ans);
      if(qr >= mid+1)
        query(rson,mid+1,r,ql,qr,ans);
    }
  }
  int query(int n,int x1,int x2,int y1,int y2){
    // printf("query:%d %d %d %d\n",x1,x2,y1,y2);
    if(x1 > x2) return 0;
    a = y1,b = y2;
    int ans = 0;
    query(1,1,n,x1,x2,ans);
    return ans;
  }
}

void build(){
  static int tmp[MAXN];
  // printf("tmp:\n");
  for(int i = 1;i<=n;i++){
    tmp[i] = a[i].r;
    // printf("%d ",tmp[i]);
  }
  // printf("\n");
  // printf("t:\n");
  // for(int i = 1;i<=cnt;i++){
  //   printf("%d ", t[i]);
  // }
  // printf("\n");
  SegTree::build(1,1,n,tmp);
}

int s[MAXN];

int getval(int x){
  return lower_bound(t+1,t+cnt+1,x) - t;
}

void solve_case(){
  int p;
  scanf("%d",&p);
  for(int i = 1;i<=p;i++){
    scanf("%d",&s[i]);
  }
  sort(s+1,s+p+1);
  s[0] = -1e9;
  int ans = 0;
  for(int i = 1;i<=p;i++){
    // printf("%d getval:%d(%d) %d(%d) ",i,getval(s[i-1]+1),s[i-1]+1,getval(s[i]+1)-1,s[i]);
    ans += SegTree::query(n,getval(s[i-1]+1),getval(s[i]+1)-1,s[i],1e9);
    // printf("ans:%d\n",ans);
  }
  printf("%d\n",ans);
}

void solve(){
  for(int i = 1;i<=m;i++){
    solve_case();
  }
}

int main(){
  init();
  build();
  solve();
  return 0;
}


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

const int MAXN = 1110000;

int n,m;
struct Line{
  int l,r;
  bool operator < (const Line x)const{
    if(l != x.l) return l < x.l;
    else return r < x.r;//???有可能有问题
  }
}a[MAXN];

namespace BIT{
  int sumn[MAXN];
  int lowbit(int x){return x & (-x);}
  int query(int x){
    // printf("q:%d\n",x);
    int ans = 0;
    while(x){
      ans += sumn[x];
      x -= lowbit(x);
    }
    return ans;
  }
  void update(int x,int v){
    // printf("upd:%d %d\n",x,v);
    while(x <= MAXN-1){
      sumn[x] += v;
      x += lowbit(x);
    }
  }
  void clear(int x){
    while(x <= MAXN-1){
      sumn[x] = 0;
      x += lowbit(x);
    }
  }
};

void init(){
  scanf("%d %d",&n,&m);
  for(int i = 1;i<=n;i++){
    scanf("%d %d",&a[i].l,&a[i].r);
  }
  sort(a+1,a+n+1);
}

set<int> S;
vector<int> v;

void solve_case(){
  int p;
  scanf("%d",&p);
  for(int i = 1;i<=p;i++){
    int x;
    scanf("%d",&x);
    v.push_back(x);
  }
  // printf("!!!!\n");
  v.push_back(-1e9);
  sort(v.begin(),v.end());
  int ans = 0,L = 1,R = 0;
  for(int i = 1;i<=p;i++){
    while(R < n && a[R+1].l <= v[i]){
      R++,BIT::update(a[R].r,1);
      S.insert(a[R].r);
    }
    while(L <= R && a[L].l <= v[i-1]){
      BIT::update(a[L].r,-1);
      S.insert(a[L].r);
      L++;
    }
    ans += BIT::query(MAXN-1) - BIT::query(v[i]-1);
    // printf("ANS:%d\n",ans);
  }
  for(auto i:S){
    BIT::clear(i);
  }
  S.clear(),v.clear();
  printf("%d\n",ans);
}

void solve(){
  for(int i = 1;i<=m;i++){
    solve_case();
  }
}

int main(){
  init();
  solve();
  return 0;
}


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

const int MAXN = 310000;

int n,m,cnt = 0;
struct Line{
  int l,r;
  bool operator < (const Line x)const{
    if(l != x.l) return l < x.l;
    else return r < x.r;//???有可能有问题
  }
}a[MAXN];

int t[MAXN];
map<int,int> S;

void init(){
  scanf("%d %d",&n,&m);
  for(int i = 1;i<=n;i++){
    scanf("%d %d",&a[i].l,&a[i].r);
    S[a[i].l] = 0;
  }
  sort(a+1,a+n+1);
  for(auto it = S.begin();it!=S.end();it++){
    it->second = ++cnt;
    t[cnt] = it->first;
  }
  for(int i = 1;i<=n;i++)
    a[i].l = S[a[i].l];
}

namespace SegTree{
  vector<int> v[MAXN<<2];
  #define lson (nown<<1)
  #define rson (nown<<1|1)
  #define mid ((l+r)>>1)
  void build(int nown,int l,int r,int *a){
    for(int i = l;i<=r;i++)
      v[nown].push_back(a[i]);
    sort(v[nown].begin(),v[nown].end());
    if(l == r) return;
    else
      build(lson,l,mid,a),build(rson,mid+1,r,a);
  }
  int a,b;
  void query(int nown,int l,int r,int ql,int qr,int &ans){
    if(ql <= l && r <= qr){
      ans += lower_bound(v[nown].begin(),v[nown].end(),b) - lower_bound(v[nown].begin(),v[nown].end(),a-1);
    }
    else{
      if(ql <= mid)
        query(lson,l,mid,ql,qr,ans);
      if(qr >= mid+1)
        query(rson,mid+1,r,ql,qr,ans);
    }
  }
  int query(int n,int x1,int x2,int y1,int y2){
    // printf("query:%d %d %d %d\n",x1,x2,y1,y2);
    if(x1 > x2) return 0;
    a = y1,b = y2;
    int ans = 0;
    query(1,1,n,x1,x2,ans);
    return ans;
  }
}

void build(){
  static int tmp[MAXN];
  // printf("tmp:\n");
  for(int i = 1;i<=n;i++){
    tmp[i] = a[i].r;
    // printf("%d ",tmp[i]);
  }
  // printf("\n");
  // printf("t:\n");
  // for(int i = 1;i<=cnt;i++){
  //   printf("%d ", t[i]);
  // }
  // printf("\n");
  SegTree::build(1,1,n,tmp);
}

int s[MAXN];

int getval(int x){
  return lower_bound(t+1,t+cnt+1,x) - t;
}

void solve_case(){
  int p;
  scanf("%d",&p);
  for(int i = 1;i<=p;i++){
    scanf("%d",&s[i]);
  }
  sort(s+1,s+p+1);
  s[0] = -1e9;
  int ans = 0;
  for(int i = 1;i<=p;i++){
    // printf("%d getval:%d(%d) %d(%d) ",i,getval(s[i-1]+1),s[i-1]+1,getval(s[i]+1)-1,s[i]);
    ans += SegTree::query(n,getval(s[i-1]+1),getval(s[i]+1)-1,s[i],1e9);
    // printf("ans:%d\n",ans);
  }
  printf("%d\n",ans);
}

void solve(){
  for(int i = 1;i<=m;i++){
    solve_case();
  }
}

int main(){
  init();
  build();
  solve();
  return 0;
}


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

namespace fast_io{
    static const int SIZE=1024*1024;char ibuf[SIZE],*_s,*_t,obuf[SIZE],*oh=obuf;inline void flush(){fwrite(obuf,1,oh-obuf,stdout);}
    inline char read(){if(_s==_t)_t=(_s=ibuf)+fread(ibuf,1,SIZE,stdin);return _s==_t?-1:*_s++;}
    template<typename T>inline void read(T&x){static char c;static bool iosig;for(iosig=0,c=read();!isdigit(c);c=read()){if(c==-1)return;iosig|=(c=='-');}for(x=0;isdigit(c);c=read())x=(((x<<2)+x)<<1)+(c^48);if(iosig)x=-x;return;}
    inline void read(char*a){static char c=read();while(c!=-1&&(c==' '||c!='\r'||c=='\n'))c=read();while(c!=-1&&c!=' '&&c!='\r'&&c!='\n')*a++=c,c=read();*a=0;}
    inline void print(char c){if(oh==obuf+SIZE)fwrite(obuf,1,SIZE,stdout),oh=obuf;*oh++=c;}
    template<typename T>inline void print(T x){static int buf[21],cnt;if(!x)print('0');else{if(x<0)print('-'),x=-x;for(cnt=0;x;x/=10)buf[++cnt]=x%10+48;while(cnt)print((char)buf[cnt--]);}}
    inline void print(char*a){while(*a)print(*a++);}
}using namespace fast_io;

const int MAXN = 1110000;

int n,m;
struct Line{
  int l,r;
  bool operator < (const Line x)const{
    if(l != x.l) return l < x.l;
    else return r < x.r;//???有可能有问题
  }
}a[MAXN];

namespace BIT{
  int sumn[MAXN];
  int lowbit(int x){return x & (-x);}
  int query(int x){
    // printf("q:%d\n",x);
    int ans = 0;
    while(x){
      ans += sumn[x];
      x -= lowbit(x);
    }
    return ans;
  }
  void update(int x,int v){
    // printf("upd:%d %d\n",x,v);
    while(x <= MAXN-1){
      sumn[x] += v;
      x += lowbit(x);
    }
  }
  void clear(int x){
    while(x <= MAXN-1){
      if(sumn[x] == 0) return;
      sumn[x] = 0;
      x += lowbit(x);
    }
  }
};

void init(){
  read(n),read(m);
  for(int i = 1;i<=n;i++){
   read(a[i].l),read(a[i].r);
  }
  sort(a+1,a+n+1);
}

int s[MAXN],cnt;

vector<int> v;

void solve_case(){
  int p;
  cnt = 0;
  read(p);
  for(int i = 1;i<=p;i++){
    int x;
    read(x);
    v.push_back(x);
  }
  // printf("!!!!\n");
  v.push_back(-1e9);
  sort(v.begin(),v.end());
  int ans = 0,L = 1,R = 0;
  for(int i = 1;i<=p;i++){
    while(R < n && a[R+1].l <= v[i]){
      R++,BIT::update(a[R].r,1);
      s[++cnt] = a[R].r;
    }
    while(L <= R && a[L].l <= v[i-1]){
      BIT::update(a[L].r,-1);
      s[++cnt] = a[R].r;
      L++;
    }
    ans += BIT::query(MAXN-1) - BIT::query(v[i]-1);
    // printf("ANS:%d\n",ans);
  }
  for(int i = 1;i<=cnt;i++) BIT::clear(s[i]);
  v.clear();
  printf("%d\n",ans);
}

void solve(){
  for(int i = 1;i<=m;i++){
    solve_case();
  }
}

int main(){
  init();
  solve();
  return 0;
}


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

const int MAXN = 310000;

int n,m,cnt = 0;
struct Line{
  int l,r;
  bool operator < (const Line x)const{
    if(l != x.l) return l < x.l;
    else return r < x.r;//???有可能有问题
  }
}a[MAXN];

int t[MAXN];
map<int,int> S;

void init(){
  scanf("%d %d",&n,&m);
  for(int i = 1;i<=n;i++){
    scanf("%d %d",&a[i].l,&a[i].r);
    S[a[i].l] = 0;
  }
  sort(a+1,a+n+1);
  for(auto it = S.begin();it!=S.end();it++){
    it->second = ++cnt;
    t[cnt] = it->first;
  }
  for(int i = 1;i<=n;i++)
    a[i].l = S[a[i].l];
}

namespace SegTree{
  vector<int> v[MAXN<<2];
  #define lson (nown<<1)
  #define rson (nown<<1|1)
  #define mid ((l+r)>>1)
  void build(int nown,int l,int r,int *a){
    for(int i = l;i<=r;i++)
      v[nown].push_back(a[i]);
    sort(v[nown].begin(),v[nown].end());
    if(l == r) return;
    else
      build(lson,l,mid,a),build(rson,mid+1,r,a);
  }
  int a,b;
  void query(int nown,int l,int r,int ql,int qr,int &ans){
    if(ql <= l && r <= qr){
      ans += lower_bound(v[nown].begin(),v[nown].end(),b) - lower_bound(v[nown].begin(),v[nown].end(),a);
    }
    else{
      if(ql <= mid)
        query(lson,l,mid,ql,qr,ans);
      if(qr >= mid+1)
        query(rson,mid+1,r,ql,qr,ans);
    }
  }
  int query(int n,int x1,int x2,int y1,int y2){
    // printf("query:%d %d %d %d\n",x1,x2,y1,y2);
    if(x1 > x2) return 0;
    a = y1,b = y2;
    int ans = 0;
    query(1,1,n,x1,x2,ans);
    return ans;
  }
}

void build(){
  static int tmp[MAXN];
  // printf("tmp:\n");
  for(int i = 1;i<=n;i++){
    tmp[i] = a[i].r;
    // printf("%d ",tmp[i]);
  }
  // printf("\n");
  // printf("t:\n");
  // for(int i = 1;i<=cnt;i++){
  //   printf("%d ", t[i]);
  // }
  // printf("\n");
  SegTree::build(1,1,n,tmp);
}

int s[MAXN];

int getval(int x){
  return lower_bound(t+1,t+cnt+1,x) - t;
}

void solve_case(){
  int p;
  scanf("%d",&p);
  for(int i = 1;i<=p;i++){
    scanf("%d",&s[i]);
  }
  sort(s+1,s+p+1);
  s[0] = -1e9;
  int ans = 0;
  for(int i = 1;i<=p;i++){
    // printf("%d getval:%d(%d) %d(%d) ",i,getval(s[i-1]+1),s[i-1]+1,getval(s[i]+1)-1,s[i]);
    ans += SegTree::query(n,getval(s[i-1]+1),getval(s[i]+1)-1,s[i],1e9);
    // printf("ans:%d\n",ans);
  }
  printf("%d\n",ans);
}

void solve(){
  for(int i = 1;i<=m;i++){
    solve_case();
  }
}

int main(){
  init();
  build();
  solve();
  return 0;
}


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

const int MAXN = 310000;

int n,m,cnt = 0;
struct Line{
  int l,r;
  bool operator < (const Line x)const{
    if(l != x.l) return l < x.l;
    else return r < x.r;//???有可能有问题
  }
}a[MAXN];

int t[MAXN],back[MAXN];
map<int,int> S;

void init(){
  scanf("%d %d",&n,&m);
  for(int i = 1;i<=n;i++){
    scanf("%d %d",&a[i].l,&a[i].r);
    S[a[i].l] = 0;
  }
  sort(a+1,a+n+1);
  for(auto it = S.begin();it!=S.end();it++){
    it->second = ++cnt;
    back[cnt] = it->first;
  }
}

namespace SegTree{
  vector<int> v[MAXN<<2];
  #define lson (nown<<1)
  #define rson (nown<<1|1)
  #define mid ((l+r)>>1)
  void build(int nown,int l,int r,int *a){
    for(int i = l;i<=r;i++)
      v[nown].push_back(a[i]);
    sort(v[nown].begin(),v[nown].end());
    if(l == r)
      return;
    else
      build(lson,l,mid,a),build(rson,mid+1,r,a);
  }
  int a,b;
  void query(int nown,int l,int r,int ql,int qr,int &ans){
    if(ql <= l && r <= qr){
      ans += upper_bound(v[nown].begin(),v[nown].end(),b) - lower_bound(v[nown].begin(),v[nown].end(),a);
    }
    else{
      if(ql <= mid)
        query(lson,l,mid,ql,qr,ans);
      if(qr >= mid+1)
        query(rson,mid+1,r,ql,qr,ans);
    }
  }
  int query(int n,int x1,int x2,int y1,int y2){
    // printf("query:%d %d %d %d\n",x1,x2,y1,y2);
    if(x1 > x2) return 0;
    a = y1,b = y2;
    int ans = 0;
    query(1,1,n,x1,x2,ans);
    return ans;
  }
}

void build(){
  static int tmp[MAXN];
  // printf("tmp:\n");
  for(int i = 1;i<=n;i++){
    tmp[i] = a[i].r;
    // printf("%d ",tmp[i]);
  }
  // printf("\n");
  for(int i = 1;i<=n;i++){
    t[i] = back[S[a[i].l]];
  }
  // printf("t:\n");
  // for(int i = 1;i<=cnt;i++){
  //   printf("%d ", t[i]);
  // }
  // printf("\n");
  SegTree::build(1,1,n,tmp);
}

int s[MAXN];
int getval(int x){
  return upper_bound(t+1,t+n+1,x) - t;
}

void solve_case(){
  int p;
  scanf("%d",&p);
  for(int i = 1;i<=p;i++) scanf("%d",&s[i]);
  sort(s+1,s+p+1);
  s[0] = -1e9;
  int ans = 0;
  for(int i = 1;i<=p;i++){
    // printf("%d getval:%d(%d) %d(%d) ",i,getval(s[i-1]),s[i-1],getval(s[i])-1,s[i]);
    ans += SegTree::query(n,getval(s[i-1]),getval(s[i])-1,s[i],1e9);
    // printf("ans:%d\n",ans);
  }
  printf("%d\n",ans);
}

void solve(){
  for(int i = 1;i<=m;i++){
    solve_case();
  }
}

int main(){
  init();
  build();
  solve();
  return 0;
}


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

const int MAXN = 210000;

int n,m,cnt = 0;
struct Line{
  int l,r;
  bool operator < (const Line x)const{
    if(l != x.l) return l < x.l;
    else return r < x.r;//???有可能有问题
  }
}a[MAXN];

int t[MAXN];
map<int,int> S;

void init(){
  scanf("%d %d",&n,&m);
  for(int i = 1;i<=n;i++){
    scanf("%d %d",&a[i].l,&a[i].r);
    S[a[i].l] = 0;
  }
  sort(a+1,a+n+1);
  for(auto it = S.begin();it!=S.end();it++){
    it->second = ++cnt;
    t[cnt] = it->first;
  }
  for(int i = 1;i<=n;i++)
    a[i].l = S[a[i].l];
}

namespace SegTree{
  vector<int> v[MAXN<<2];
  #define lson (nown<<1)
  #define rson (nown<<1|1)
  #define mid ((l+r)>>1)
  void build(int nown,int l,int r,int *a){
    for(int i = l;i<=r;i++)
      v[nown].push_back(a[i]);
    sort(v[nown].begin(),v[nown].end());
    if(l == r) return;
    else
      build(lson,l,mid,a),build(rson,mid+1,r,a);
  }
  int a,b;
  void query(int nown,int l,int r,int ql,int qr,int &ans){
    if(ql <= l && r <= qr){
      ans += lower_bound(v[nown].begin(),v[nown].end(),b) - lower_bound(v[nown].begin(),v[nown].end(),a);
    }
    else{
      if(ql <= mid)
        query(lson,l,mid,ql,qr,ans);
      if(qr >= mid+1)
        query(rson,mid+1,r,ql,qr,ans);
    }
  }
  int query(int n,int x1,int x2,int y1,int y2){
    // printf("query:%d %d %d %d\n",x1,x2,y1,y2);
    if(x1 > x2) return 0;
    a = y1,b = y2;
    int ans = 0;
    query(1,1,n,x1,x2,ans);
    return ans;
  }
}

void build(){
  static int tmp[MAXN];
  // printf("tmp:\n");
  for(int i = 1;i<=n;i++){
    tmp[i] = a[i].r;
    // printf("%d ",tmp[i]);
  }
  // printf("\n");
  // printf("t:\n");
  // for(int i = 1;i<=cnt;i++){
  //   printf("%d ", t[i]);
  // }
  // printf("\n");
  SegTree::build(1,1,n,tmp);
}

int s[MAXN];

int getval(int x){
  return lower_bound(t+1,t+cnt+1,x) - t;
}

void solve_case(){
  int p;
  scanf("%d",&p);
  for(int i = 1;i<=p;i++){
    scanf("%d",&s[i]);
  }
  sort(s+1,s+p+1);
  s[0] = -1e9;
  int ans = 0;
  for(int i = 1;i<=p;i++){
    // printf("%d getval:%d(%d) %d(%d) ",i,getval(s[i-1]+1),s[i-1]+1,getval(s[i]+1)-1,s[i]);
    ans += SegTree::query(n,getval(s[i-1]+1),getval(s[i]+1)-1,s[i],1e9);
    // printf("ans:%d\n",ans);
  }
  printf("%d\n",ans);
}

void solve(){
  for(int i = 1;i<=m;i++){
    solve_case();
  }
}

int main(){
  init();
  build();
  solve();
  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;
const int nmax = 3e6+5;
int ftree[nmax];
int fget(int pos){
	if(pos==0)
		return 0;
	return ftree[pos]+fget(pos-(pos&(-pos)));
}
void fadd(int pos, int val){
	if(pos>=nmax)
		return;
	ftree[pos]+=val;
	fadd(pos+(pos&(-pos)),val);
}
int main(){
	ios_base::sync_with_stdio(false);
	int n,m;
	cin >> n >> m;
	vector<pair<int,int> > intervals(n);
	vector<int> points;
	for(int i = 0; i < n; ++i){
		cin >> intervals[i].first >> intervals[i].second;
		points.push_back(intervals[i].first);
		points.push_back(intervals[i].second);
	}
	sort(points.begin(),points.end());
	points.resize(unique(points.begin(),points.end())-points.begin());
	int L = nmax-1;
	for(int i = 0; i < n; ++i){
	//	intervals[i].first = lower_bound(points.begin(),points.end(),intervals[i].first)-points.begin()+1;
	//	intervals[i].second = lower_bound(points.begin(),points.end(),intervals[i].second)-points.begin()+1;
	}
	sort(intervals.begin(),intervals.end());
	vector<pair<int,int> > queries;
	vector<vector<int> > actual(m);
	vector<int> ans;
	for(int i = 0; i < m; ++i){
		int k;
		cin >> k;
//		cout << '\t' << k << '\n';
		actual[i].resize(k);
		for(int j = 0; j < k; ++j)
			cin >> actual[i][j];
		actual[i].insert(actual[i].begin(),-1);
		actual[i].push_back(L);
		k+=2;
		for(int j = 0; j < k-1; ++j)
			queries.push_back(make_pair(actual[i][j]+1,actual[i][j+1]-1));
//		for(int j = 0; j < k; ++j) cout << actual[i][j] << " \n"[j==k-1];
	}
	sort(queries.begin(),queries.end());
	for(int i = 0; i < n; ++i)
		fadd(intervals[i].second,1);
	int int_id = 0;
//	for(int i = 0; i < intervals.size(); ++i) cout << intervals[i].first << ' ' << intervals[i].second << '\n';
	for(int i = 0; i < queries.size(); ++i){
		while(int_id < n && queries[i].first > intervals[int_id].first){
			fadd(intervals[int_id].second,-1);
			int_id++;
		}
		ans.push_back(fget(queries[i].second));
		//cout << queries[i].first << ' ' << queries[i].second << ' ' << ans[i] << '\n';
	}
	//cout << queries.size() << ' ' << ans.size() << '\n';
	for(int i = 0; i < m; ++i){
		int cur = n;
		for(int j = 0; j < actual[i].size()-1; ++j){
			pair<int,int> ask = make_pair(actual[i][j]+1,actual[i][j+1]-1);
			int qid = lower_bound(queries.begin(),queries.end(),ask)-queries.begin();
			assert(queries[qid]==ask);
			cur -= ans[qid];
		}
		cout << cur << '\n';
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int pmax = 1e6+6;
int n,m;
int rless[pmax],rmore[pmax],lless[pmax],lmore[pmax],rat[pmax],lat[pmax];
int inside(int l, int r){
	if(l>r)
		return 0;
	return n - rmore[r] - lless[l];
}
int main(){
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	for(int i = 0; i < n; ++i){
		int a,b;
		cin >> a >> b;
		rless[b+1]++;
		rmore[b-1]++;
		rat[b]++;
		lless[a+1]++;
		lmore[a-1]++;
		lat[a]++;
	}
	for(int i = 1; i < pmax; ++i){
		rless[i]+=rless[i-1];
		lless[i]+=lless[i-1];
	}
	for(int i = pmax-2; i >= 0; --i){
		rmore[i]+=rmore[i+1];
		lmore[i]+=lmore[i+1];
	}
	for(int test = 1; test <= m; ++test){
		int k;
		cin >> k;
		vector<int> p(k);
		for(int i = 0; i < k; ++i)
			cin >> p[i];
		int start = p[0], finish = p[k-1];
		int ans = 0;
		ans+=lless[finish]-rless[start];
		ans+=rmore[start]-lmore[finish];
		ans-=inside(start,finish);
		for(int i = 0; i < k-1; ++i)
			ans-=inside(p[i]+1,p[i+1]-1);
		cout << ans << '\n';
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;
const int nmax = 3e6+5;
int ftree[nmax];
int fget(int pos){
	if(pos==0)
		return 0;
	return ftree[pos]+fget(pos-(pos&(-pos)));
}
void fadd(int pos, int val){
	if(pos>=nmax)
		return;
	ftree[pos]+=val;
	fadd(pos+(pos&(-pos)),val);
}
int main(){
	ios_base::sync_with_stdio(false);
	int n,m;
	cin >> n >> m;
	vector<pair<int,int> > intervals(n);
	vector<int> points;
	for(int i = 0; i < n; ++i){
		cin >> intervals[i].first >> intervals[i].second;
		points.push_back(intervals[i].first);
		points.push_back(intervals[i].second);
	}
	sort(points.begin(),points.end());
	points.resize(unique(points.begin(),points.end())-points.begin());
	int L = points.size()+5;
	for(int i = 0; i < n; ++i){
	//	intervals[i].first = lower_bound(points.begin(),points.end(),intervals[i].first)-points.begin()+1;
	//	intervals[i].second = lower_bound(points.begin(),points.end(),intervals[i].second)-points.begin()+1;
	}
	sort(intervals.begin(),intervals.end());
	vector<pair<int,int> > queries;
	vector<vector<int> > actual(m);
	vector<int> ans;
	for(int i = 0; i < m; ++i){
		int k;
		cin >> k;
//		cout << '\t' << k << '\n';
		actual[i].resize(k);
		for(int j = 0; j < k; ++j)
			cin >> actual[i][j];
		actual[i].insert(actual[i].begin(),-1);
		actual[i].push_back(L);
		k+=2;
		for(int j = 0; j < k-1; ++j)
			queries.push_back(make_pair(actual[i][j]+1,actual[i][j+1]-1));
//		for(int j = 0; j < k; ++j) cout << actual[i][j] << " \n"[j==k-1];
	}
	sort(queries.begin(),queries.end());
	for(int i = 0; i < n; ++i)
		fadd(intervals[i].second,1);
	int int_id = 0;
//	for(int i = 0; i < intervals.size(); ++i) cout << intervals[i].first << ' ' << intervals[i].second << '\n';
	for(int i = 0; i < queries.size(); ++i){
		while(int_id < n && queries[i].first > intervals[int_id].first){
			fadd(intervals[int_id].second,-1);
			int_id++;
		}
		ans.push_back(fget(queries[i].second));
		//cout << queries[i].first << ' ' << queries[i].second << ' ' << ans[i] << '\n';
	}
	//cout << queries.size() << ' ' << ans.size() << '\n';
	for(int i = 0; i < m; ++i){
		int cur = n;
		for(int j = 0; j < actual[i].size()-1; ++j){
			pair<int,int> ask = make_pair(actual[i][j]+1,actual[i][j+1]-1);
			int qid = lower_bound(queries.begin(),queries.end(),ask)-queries.begin();
			assert(queries[qid]==ask);
			cur -= ans[qid];
		}
		cout << cur << '\n';
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;
const int nmax = 3e5+5;
int ftree[nmax];
int fget(int pos){
	if(pos==0)
		return 0;
	return ftree[pos]+fget(pos-(pos&(-pos)));
}
void fadd(int pos, int val){
	if(pos>=nmax)
		return;
	ftree[pos]+=val;
	fadd(pos+(pos&(-pos)),val);
}
int main(){
	ios_base::sync_with_stdio(false);
	int n,m;
	cin >> n >> m;
	vector<pair<int,int> > intervals(n);
	vector<int> points;
	for(int i = 0; i < n; ++i){
		cin >> intervals[i].first >> intervals[i].second;
		points.push_back(intervals[i].first);
		points.push_back(intervals[i].second);
	}
	sort(points.begin(),points.end());
	points.resize(unique(points.begin(),points.end())-points.begin());
	int L = points.size()+5;
	for(int i = 0; i < n; ++i){
		intervals[i].first = lower_bound(points.begin(),points.end(),intervals[i].first)-points.begin()+1;
		intervals[i].second = lower_bound(points.begin(),points.end(),intervals[i].second)-points.begin()+1;
	}
	sort(intervals.begin(),intervals.end());
	vector<pair<int,int> > queries;
	vector<vector<int> > actual(m);
	vector<int> ans;
	for(int i = 0; i < m; ++i){
		int k;
		cin >> k;
		actual[i].resize(k);
		for(int j = 0; j < k; ++j)
			cin >> actual[i][j];
		actual[i].insert(actual[i].begin(),-1);
		actual[i].push_back(L);
		k+=2;
		for(int j = 0; j < k-1; ++j)
			queries.push_back(make_pair(actual[i][j]+1,actual[i][j+1]-1));
//		for(int j = 0; j < k; ++j) cout << actual[i][j] << " \n"[j==k-1];
	}
	sort(queries.begin(),queries.end());
	for(int i = 0; i < n; ++i)
		fadd(intervals[i].second,1);
	int int_id = 0;
//	for(int i = 0; i < intervals.size(); ++i) cout << intervals[i].first << ' ' << intervals[i].second << '\n';
	for(int i = 0; i < queries.size(); ++i){
		while(int_id < n && queries[i].first > intervals[int_id].first){
			fadd(intervals[int_id].second,-1);
			int_id++;
		}
		ans.push_back(fget(queries[i].second));
		//cout << queries[i].first << ' ' << queries[i].second << ' ' << ans[i] << '\n';
	}
	//cout << queries.size() << ' ' << ans.size() << '\n';
	for(int i = 0; i < m; ++i){
		int cur = n;
		for(int j = 0; j < actual[i].size()-1; ++j){
			pair<int,int> ask = make_pair(actual[i][j]+1,actual[i][j+1]-1);
			int qid = lower_bound(queries.begin(),queries.end(),ask)-queries.begin();
			assert(queries[qid]==ask);
			cur -= ans[qid];
		}
		cout << cur << '\n';
	}
}


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

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
//#define int long long

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef pair <ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <ll> vll;
typedef double ld;

const int INF = (int)2e9;
const int mod = (int)1e9 + 7;
const int N = (int)1e6;
const ll LLINF = (ll)1e18 + 10;
const ld pi = acos(-1.0);

template <typename T1, typename T2> bool umin(T1 &x, T2 y){if(x>y) return x=y, true;return false;}
template <typename T1, typename T2> bool umax(T1 &x, T2 y){if(x<y) return x=y, true;return false;}

template <typename T>
T getint() {
    char c = getchar();
    T p = 1, x = 0;
    while(c == ' ' || c == '\n') c = getchar();
    if(c == '-') p = -1, c = getchar();
    while(c >= '0' && c <= '9')
        x = x * 10 + c - '0', c = getchar();
    return x * p;
}

struct tree {
    int tl, tr, sum;
    tree *le, *ri;
    tree() {
        le = ri = NULL;
        sum = 0;
    }
    tree(int l, int r) {
        tl = l, tr = r;
        if(l == r)
            return;
        le = new tree(l, (l+r)/2);
        ri = new tree((l+r)/2+1, r);
    }

    tree(int l, int r, int val) {
        tl = l, tr = r, sum = val;
        le = ri = NULL;
    }

    tree(tree *l, tree *r) {
        le = l, ri = r;
        tl = l->tl; tr = r->tr;
        sum = l->sum + r->sum;
    }

    tree* modify(int id, int val) {
        if(tl == tr)
            return new tree(tl, tr, sum+val);
        if(id <= (tl+tr)/2)
            return new tree(le->modify(id, val), ri);
        else
            return new tree(le, ri->modify(id, val));

    }

    int get(int l, int r) {
        if(tl > r || tr < l) return 0;
        if(l <= tl && tr <= r) return sum;
        return le->get(l, r) + ri->get(l, r);
    }
};

tree* roots[N];
pii p[N];

int n, m;
int main() {
    //ios_base::sync_with_stdio(0);
 //   freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);
    n = getint<int>(); m = getint<int>();
    roots[0] = new tree(1, 1000000);
    for(int i = 0; i < n; ++i) {
        p[i].F = getint<int>(); p[i].S = getint<int>();
    }
    sort(p, p + n);
    for(int i = 0; i < n; ++i) {
        roots[i+1] = roots[i]->modify(p[i].S, 1);
    }
    for(int i = 0; i < m; ++i) {
        int k, r = 0, ans = 0; cin >> k;
        for(int i = 0; i < k; ++i) {
            int x; cin >> x;
            int pos = upper_bound(p, p+n, mp(x, INF)) - p;
            ans += roots[pos]->get(x, 1000000) -
            roots[r]->get(x, 1000000); r = pos;
        }
        printf("%d\n", ans);
    }
    return 0;
}


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

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
//#define int long long

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef pair <ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <ll> vll;
typedef double ld;

const int INF = (int)2e9;
const int mod = (int)1e9 + 7;
const int N = (int)1e6;
const ll LLINF = (ll)1e18 + 10;
const ld pi = acos(-1.0);

template <typename T1, typename T2> bool umin(T1 &x, T2 y){if(x>y) return x=y, true;return false;}
template <typename T1, typename T2> bool umax(T1 &x, T2 y){if(x<y) return x=y, true;return false;}

template <typename T>
T getint() {
    char c = getchar();
    T p = 1, x = 0;
    while(c == ' ' || c == '\n') c = getchar();
    if(c == '-') p = -1, c = getchar();
    while(c >= '0' && c <= '9')
        x = x * 10 + c - '0', c = getchar();
    return x * p;
}

struct tree {
    int tl, tr, sum;
    tree *le, *ri;
    tree(int l, int r) {
        tl = l, tr = r; sum = 0;
        if(l == r)
            return;
        le = new tree(l, (l+r)/2);
        ri = new tree((l+r)/2+1, r);
    }

    tree(int l, int r, int val) {
        tl = l, tr = r, sum = val;
        le = ri = NULL;
    }

    tree(tree *l, tree *r) {
        le = l, ri = r;
        tl = l->tl; tr = r->tr;
        sum = l->sum + r->sum;
    }

    tree* modify(int id, int val) {
        if(tl == tr)
            return new tree(tl, tr, sum+val);
        if(id <= (tl+tr)/2)
            return new tree(le->modify(id, val), ri);
        else
            return new tree(le, ri->modify(id, val));

    }

    int get(int l, int r) {
        if(tl > r || tr < l) return 0;
        if(l <= tl && tr <= r) return sum;
        return le->get(l, r) + ri->get(l, r);
    }
};

tree* roots[N];
pii p[N];

int n, m;
int main() {
   // ios_base::sync_with_stdio(0);
 //   freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    n = getint<int>(); m = getint<int>();
    roots[0] = new tree(1, 1000000);
    for(int i = 0; i < n; ++i) {
        p[i].F = getint<int>(); p[i].S = getint<int>();
    }
    sort(p, p + n);
    for(int i = 0; i < n; ++i) {
        roots[i+1] = roots[i]->modify(p[i].S, 1);
    }
    for(int i = 0; i < m; ++i) {
        int k, r = 0, ans = 0; cin >> k;
        for(int i = 0; i < k; ++i) {
            int x = getint<int>();
            int pos = upper_bound(p, p+n, mp(x, INF)) - p;
            ans += roots[pos]->get(x, 1000000) -
            roots[r]->get(x, 1000000); r = pos;
        }
        printf("%d\n", ans);
    }
    return 0;
}


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

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
//#define int long long

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef pair <ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <ll> vll;
typedef double ld;

const int INF = (int)2e9;
const int mod = (int)1e9 + 7;
const int N = (int)1e6;
const ll LLINF = (ll)1e18 + 10;
const ld pi = acos(-1.0);

template <typename T1, typename T2> bool umin(T1 &x, T2 y){if(x>y) return x=y, true;return false;}
template <typename T1, typename T2> bool umax(T1 &x, T2 y){if(x<y) return x=y, true;return false;}

template <typename T>
T getint() {
    char c = getchar();
    T p = 1, x = 0;
    while(c == ' ' || c == '\n') c = getchar();
    if(c == '-') p = -1, c = getchar();
    while(c >= '0' && c <= '9')
        x = x * 10 + c - '0', c = getchar();
    return x * p;
}

struct tree {
    int tl, tr, sum;
    tree *le, *ri;
    tree() {
        le = ri = NULL;
        sum = 0;
    }
    tree(int l, int r) {
        tl = l, tr = r;
        if(l == r)
            return;
        le = new tree(l, (l+r)/2);
        ri = new tree((l+r)/2+1, r);
    }

    tree(int l, int r, int val) {
        tl = l, tr = r, sum = val;
        le = ri = NULL;
    }

    tree(tree *l, tree *r) {
        le = l, ri = r;
        tl = l->tl; tr = r->tr;
        sum = l->sum + r->sum;
    }

    tree* modify(int id, int val) {
        if(tl == tr)
            return new tree(tl, tr, sum+val);
        if(id <= (tl+tr)/2)
            return new tree(le->modify(id, val), ri);
        else
            return new tree(le, ri->modify(id, val));

    }

    int get(int l, int r) {
        if(tl > r || tr < l) return 0;
        if(l <= tl && tr <= r) return sum;
        return le->get(l, r) + ri->get(l, r);
    }
};

tree* roots[4*N];
pii p[N];

int n, m;
int main() {
    ios_base::sync_with_stdio(0);
 //   freopen("input.txt", "r", stdin);
 //   freopen("output.txt", "w", stdout);
    cin >> n >> m;
    roots[0] = new tree(1, 1000000);
    for(int i = 0; i < n; ++i) {
        cin >> p[i].F >> p[i].S;
    }
    sort(p, p + n);
    for(int i = 0; i < n; ++i) {
        roots[i+1] = roots[i]->modify(p[i].S, 1);
    }
    for(int i = 0; i < m; ++i) {
        int k, r = 0, ans = 0; cin >> k;
        for(int i = 0; i < k; ++i) {
            int x; cin >> x;
            int pos = upper_bound(p, p+n, mp(x, INF)) - p;
            ans += roots[pos]->get(x, 1000000) -
            roots[r]->get(x, 1000000); r = pos;
        }
        cout << ans << '\n';
    }
    return 0;
}


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

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
//#define int long long

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef pair <ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <ll> vll;
typedef double ld;

const int INF = (int)2e9;
const int mod = (int)1e9 + 7;
const int N = (int)1e6;
const ll LLINF = (ll)1e18 + 10;
const ld pi = acos(-1.0);

template <typename T1, typename T2> bool umin(T1 &x, T2 y){if(x>y) return x=y, true;return false;}
template <typename T1, typename T2> bool umax(T1 &x, T2 y){if(x<y) return x=y, true;return false;}

template <typename T>
T getint() {
    char c = getchar();
    T p = 1, x = 0;
    while(c == ' ' || c == '\n') c = getchar();
    if(c == '-') p = -1, c = getchar();
    while(c >= '0' && c <= '9')
        x = x * 10 + c - '0', c = getchar();
    return x * p;
}

struct tree {
    int tl, tr, sum;
    tree *le, *ri;
    tree(int l, int r) {
        tl = l, tr = r; sum = 0;
        if(l == r)
            return;
        le = new tree(l, (l+r)/2);
        ri = new tree((l+r)/2+1, r);
    }

    tree(int l, int r, int val) {
        tl = l, tr = r, sum = val;
        le = ri = NULL;
    }

    tree(tree *l, tree *r) {
        le = l, ri = r;
        tl = l->tl; tr = r->tr;
        sum = l->sum + r->sum;
    }

    tree* modify(int id, int val) {
        if(tl == tr)
            return new tree(tl, tr, sum+val);
        if(id <= (tl+tr)/2)
            return new tree(le->modify(id, val), ri);
        else
            return new tree(le, ri->modify(id, val));

    }

    int get(int l, int r) {
        if(tl > r || tr < l) return 0;
        if(l <= tl && tr <= r) return sum;
        return le->get(l, r) + ri->get(l, r);
    }
};

tree* roots[N];
pii p[N];

int n, m;
int main() {
   // ios_base::sync_with_stdio(0);
//    freopen("input.txt", "r", stdin);
 //   freopen("output.txt", "w", stdout);
    n = getint<int>(); m = getint<int>();
    roots[0] = new tree(1, 1000000);
    for(int i = 0; i < n; ++i) {
        p[i].F = getint<int>(); p[i].S = getint<int>();
    }
    sort(p, p + n);
    for(int i = 0; i < n; ++i) {
        roots[i+1] = roots[i]->modify(p[i].S, 1);
    }
    for(int i = 0; i < m; ++i) {
        int k, r = 0, ans = 0; cin >> k;
        for(int i = 0; i < k; ++i) {
            int x; cin >> x;
            int pos = upper_bound(p, p+n, mp(x, INF)) - p;
            ans += roots[pos]->get(x, 1000000) -
            roots[r]->get(x, 1000000); r = pos;
        }
        printf("%d\n", ans);
    }
    return 0;
}


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

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
//#define int long long

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef pair <ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <ll> vll;
typedef double ld;

const int INF = (int)2e9;
const int mod = (int)1e9 + 7;
const int N = (int)1e6;
const ll LLINF = (ll)1e18 + 10;
const ld pi = acos(-1.0);

template <typename T1, typename T2> bool umin(T1 &x, T2 y){if(x>y) return x=y, true;return false;}
template <typename T1, typename T2> bool umax(T1 &x, T2 y){if(x<y) return x=y, true;return false;}

template <typename T>
T getint() {
    char c = getchar();
    T p = 1, x = 0;
    while(c == ' ' || c == '\n') c = getchar();
    if(c == '-') p = -1, c = getchar();
    while(c >= '0' && c <= '9')
        x = x * 10 + c - '0', c = getchar();
    return x * p;
}

struct tree {
    int tl, tr, sum;
    tree *le, *ri;
    tree() {
        le = ri = NULL;
        sum = 0;
    }
    tree(int l, int r) {
        tl = l, tr = r;
        if(l == r)
            return;
        le = new tree(l, (l+r)/2);
        ri = new tree((l+r)/2+1, r);
    }

    tree(int l, int r, int val) {
        tl = l, tr = r, sum = val;
        le = ri = NULL;
    }

    tree(tree *l, tree *r) {
        le = l, ri = r;
        tl = l->tl; tr = r->tr;
        sum = l->sum + r->sum;
    }

    tree* modify(int id, int val) {
        if(tl == tr)
            return new tree(tl, tr, sum+val);
        if(id <= (tl+tr)/2)
            return new tree(le->modify(id, val), ri);
        else
            return new tree(le, ri->modify(id, val));

    }

    int get(int l, int r) {
        if(tl > r || tr < l) return 0;
        if(l <= tl && tr <= r) return sum;
        return le->get(l, r) + ri->get(l, r);
    }
};

tree* roots[N];
pii p[N];

int n, m;
int main() {
    ios_base::sync_with_stdio(0);
//    freopen("input.txt", "r", stdin);
 //   freopen("output.txt", "w", stdout);
    cin >> n >> m;
    roots[0] = new tree(1, 1000000);
    for(int i = 0; i < n; ++i) {
        cin >> p[i].F >> p[i].S;
    }
    sort(p, p + n);
    for(int i = 0; i < n; ++i) {
        roots[i+1] = roots[i]->modify(p[i].S, 1);
    }
    for(int i = 0; i < m; ++i) {
        int k, r = 0, ans = 0; cin >> k;
        for(int i = 0; i < k; ++i) {
            int x; cin >> x;
            int pos = upper_bound(p, p+n, mp(x, INF)) - p;
            ans += roots[pos]->get(x, 1000000) -
            roots[r]->get(x, 1000000); r = pos;
        }
        cout << ans << '\n';
    }
    return 0;
}


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

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
//#define int long long

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef pair <ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <ll> vll;
typedef double ld;

const int INF = (int)2e9;
const int mod = (int)1e9 + 7;
const int N = (int)1e6;
const ll LLINF = (ll)1e18 + 10;
const ld pi = acos(-1.0);

template <typename T1, typename T2> bool umin(T1 &x, T2 y){if(x>y) return x=y, true;return false;}
template <typename T1, typename T2> bool umax(T1 &x, T2 y){if(x<y) return x=y, true;return false;}

template <typename T>
T getint() {
    char c = getchar();
    T p = 1, x = 0;
    while(c == ' ' || c == '\n') c = getchar();
    if(c == '-') p = -1, c = getchar();
    while(c >= '0' && c <= '9')
        x = x * 10 + c - '0', c = getchar();
    return x * p;
}

struct tree {
    int tl, tr, sum;
    tree *le, *ri;
    tree(int l, int r) {
        tl = l, tr = r; sum = 0;
        if(l == r)
            return;
        le = new tree(l, (l+r)/2);
        ri = new tree((l+r)/2+1, r);
    }

    tree(int l, int r, int val) {
        tl = l, tr = r, sum = val;
        le = ri = NULL;
    }

    tree(tree *l, tree *r) {
        le = l, ri = r;
        tl = l->tl; tr = r->tr;
        sum = l->sum + r->sum;
    }

    tree* modify(int id, int val) {
        if(tl == tr)
            return new tree(tl, tr, sum+val);
        if(id <= (tl+tr)/2)
            return new tree(le->modify(id, val), ri);
        else
            return new tree(le, ri->modify(id, val));

    }

    int get(int l, int r) {
        if(tl > r || tr < l) return 0;
        if(l <= tl && tr <= r) return sum;
        return le->get(l, r) + ri->get(l, r);
    }
};

tree* roots[N];
pii p[N];

int n, m;
int main() {
   // ios_base::sync_with_stdio(0);
 //   freopen("input.txt", "r", stdin);
 //   freopen("output.txt", "w", stdout);
    n = getint<int>(); m = getint<int>();
    roots[0] = new tree(1, 1000000);
    for(int i = 0; i < n; ++i) {
        p[i].F = getint<int>(); p[i].S = getint<int>();
    }
    sort(p, p + n);
    for(int i = 0; i < n; ++i) {
        roots[i+1] = roots[i]->modify(p[i].S, 1);
    }
    for(int i = 0; i < m; ++i) {
        int k = getint<int>(), r = 0, ans = 0;
        for(int i = 0; i < k; ++i) {
            int x = getint<int>();
            int pos = upper_bound(p, p+n, mp(x, INF)) - p;
            ans += roots[pos]->get(x, 1000000) -
            roots[r]->get(x, 1000000); r = pos;
        }
        printf("%d\n", ans);
    }
    return 0;
}


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

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
//#define int long long

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef pair <ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <ll> vll;
typedef double ld;

const int INF = (int)2e9;
const int mod = (int)1e9 + 7;
const int N = (int)1e6;
const ll LLINF = (ll)1e18 + 10;
const ld pi = acos(-1.0);

template <typename T1, typename T2> bool umin(T1 &x, T2 y){if(x>y) return x=y, true;return false;}
template <typename T1, typename T2> bool umax(T1 &x, T2 y){if(x<y) return x=y, true;return false;}

template <typename T>
T getint() {
    char c = getchar();
    T p = 1, x = 0;
    while(c == ' ' || c == '\n') c = getchar();
    if(c == '-') p = -1, c = getchar();
    while(c >= '0' && c <= '9')
        x = x * 10 + c - '0', c = getchar();
    return x * p;
}

struct tree {
    int tl, tr, sum;
    tree *le, *ri;
    tree(int l, int r) {
        tl = l, tr = r; sum = 0;
        if(l == r)
            return;
        le = new tree(l, (l+r)/2);
        ri = new tree((l+r)/2+1, r);
    }

    tree(int l, int r, int val) {
        tl = l, tr = r, sum = val;
        le = ri = NULL;
    }

    tree(tree *l, tree *r) {
        le = l, ri = r;
        tl = l->tl; tr = r->tr;
        sum = l->sum + r->sum;
    }

    tree* modify(int id, int val) {
        if(tl == tr)
            return new tree(tl, tr, sum+val);
        if(id <= (tl+tr)/2)
            return new tree(le->modify(id, val), ri);
        else
            return new tree(le, ri->modify(id, val));

    }

    int get(int l, int r) {
        if(tl > r || tr < l) return 0;
        if(l <= tl && tr <= r) return sum;
        return le->get(l, r) + ri->get(l, r);
    }
};

tree* roots[N];
pii p[N];

int n, m;
int main() {
    ios_base::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
 //   freopen("output.txt", "w", stdout);
    cin >> n >> m;
    roots[0] = new tree(1, 1000000);
    for(int i = 0; i < n; ++i) {
        cin >> p[i].F >> p[i].S;
    }
    sort(p, p + n);
    for(int i = 0; i < n; ++i) {
        roots[i+1] = roots[i]->modify(p[i].S, 1);
    }
    for(int i = 0; i < m; ++i) {
        int k, r = 0, ans = 0; cin >> k;
        for(int i = 0; i < k; ++i) {
            int x; cin >> x;
            int pos = upper_bound(p, p+n, mp(x, INF)) - p;
            ans += roots[pos]->get(x, 1000000) -
            roots[r]->get(x, 1000000); r = pos;
        }
        cout << ans << '\n';
    }
    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 + 2];

    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 ;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[L].pb(ii(prev  , i));
            }

           rep(i  , 1 , L + 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;
}