#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <cmath>
#include <sstream>
#include <ctime>
#include <memory.h>
#define forn(i,n) for (int i = 0; i < (int)(n); i++)
#define forv(i, a) for(int i=0; i<(int)a.size(); i++)
#define mset(a, val) memset(a, val, sizeof(a))
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define VI vector< int >
#define VS vector< string >
#define PII pair< int,int >
#define PDD pair< double,double >
#define PIS pair< int, string >
#define sqr(a) ((a)*(a))
#define cube(a) ((a)*(a)*(a))
#define pi 3.1415926535897932384626433832795
#define PI pi
#define iinf 1000000000
#define sinf 10000
#define eps 1e-12
#define lng long long
#define X first
#define Y second
using namespace std;
#define prev asdprev
#define exit(a) { if (a) cerr<<"oops "<<a<<endl; exit(a); }

#define max(a, b) ((a>b)?a:b)

int segtree[800000];
int len;

void build(int i=1, int tl=1, int tr=len){
    if(tl==tr) segtree[i]=1;
    else{
        int tc=(tl+tr)/2;

        build(i*2, tl, tc);
        build(i*2+1, tc+1, tr);

        segtree[i]=segtree[i*2]+segtree[i*2+1];
    }
}

void setnul(int pos, int i=1, int tl=1, int tr=len){
    if(tl==tr && tl==pos){
        segtree[i]=0;
        return;
    }

    int tc=(tl+tr)/2;

    if(pos<=tc) setnul(pos, i*2, tl, tc);
    else setnul(pos, i*2+1, tc+1, tr);
    segtree[i]=segtree[i*2]+segtree[i*2+1];
}

int get(int r, int l=1, int i=1, int tl=1, int tr=len){
    if(tl==l && tr==r) return segtree[i];

    int tc=(tl+tr)/2;
    if(r<=tc) return get(r, l, i*2, tl, tc);
    else if(l>tc) return get(r, l,  i*2+1, tc+1, tr);
    else{
        return get(tc, l,  i*2, tl, tc) + get(r, tc+1,  i*2+1, tc+1, tr);
    }
}

int findit(int x){
    int b=1, e=len;

    while(b<e){
        int m=(b+e)/2;

        int cur=get(m);
        if(cur==x) e=m;
        else if(cur<x) b=m+1;
        else e=m-1;
    }
    return b;
}

char str[300000];
int del[26][20000];
int delcnt[26];
bool deleted[300000];

#define taska "intersection"
int main() {
#ifdef __ASD__
    freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#else
    //freopen(taska".in", "r", stdin);freopen(taska".out", "w", stdout);
    freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#endif

    int n, k;
    string s;
    cin>>k;
    cin>>s;

    len=(int)s.size();
    forn(i, k){
        forv(j, s)
            str[i*len+j]=s[j];
    }

    len*=k;

    cin>>n;
    forn(i, n){
        int p;
        char c;

        cin>>p>>c;

        del[c-'a'][delcnt[c-'a']++]=p;
    }

    forn(ch, 26){
        build();
        mset(deleted, 0);

        forn(i, delcnt[ch]){
            int pos=findit(del[ch][i]);
            del[ch][i]=pos;

            setnul(pos);
            deleted[pos]=true;
        }

        int cnt=0;
        if(delcnt[ch]>0)
        forn(i, len)
            if(str[i]==ch+'a'){
                ++cnt;
                if(deleted[cnt]) str[i]='!';
            }

    }

    forn(i, len)
        if(str[i]!='!') printf("%c", str[i]);

    return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <cmath>
#include <sstream>
#include <ctime>
#include <memory.h>
#define forn(i,n) for (int i = 0; i < (int)(n); i++)
#define forv(i, a) for(int i=0; i<(int)a.size(); i++)
#define mset(a, val) memset(a, val, sizeof(a))
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define VI vector< int >
#define VS vector< string >
#define PII pair< int,int >
#define PDD pair< double,double >
#define PIS pair< int, string >
#define sqr(a) ((a)*(a))
#define cube(a) ((a)*(a)*(a))
#define pi 3.1415926535897932384626433832795
#define PI pi
#define iinf 1000000000
#define sinf 10000
#define eps 1e-12
#define lng long long
#define X first
#define Y second
using namespace std;
#define prev asdprev
#define exit(a) { if (a) cerr<<"oops "<<a<<endl; exit(a); }

#define max(a, b) ((a>b)?a:b)

int segtree[800000];

void add(int val, int l, int r=200005, int i=1, int tl=0, int tr=200005){
    if(l==tl && r==tr) {
        segtree[i]+=val;
        return;
    }

    int tc=(tl+tr)/2;

    if(r<=tc) add(val, l, r, i*2, tl, tc);
    else if(l>tc) add(val, l, r, i*2+1, tc+1, tr);
    else{
        add(val, l, tc, i*2, tl, tc);
        add(val, tc+1, r, i*2+1, tc+1, tr);
    }
}

int get(int pos, int i=1, int tl=0, int tr=200005){
    if(tl==tr && tl==pos) return segtree[i];

    int tc=(tl+tr)/2;
    int ans=0;

    if(pos<=tc) ans=get(pos, i*2, tl, tc);
    else ans=get(pos, i*2+1, tc+1, tr);

    return ans+segtree[i];
}

char str[300000];
int del[26][20000];
int delcnt[26];

#define taska "intersection"
int main() {
#ifdef __ASD__
    freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#else
    //freopen(taska".in", "r", stdin);freopen(taska".out", "w", stdout); freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#endif

    int n, k;
    string s;
    cin>>k;
    cin>>s;

    int len=(int)s.size();
    forn(i, k){
        forv(j, s)
            str[i*len+j]=s[j];
    }

    len*=k;

    cin>>n;
    forn(i, n){
        int p;
        char c;

        cin>>p>>c;

        del[c-'a'][delcnt[c-'a']++]=p;
    }

    forn(ch, 26){
        mset(segtree, 0);

        forn(i, delcnt[ch]){
            int pos=get(del[ch][i]);

            add(1, del[ch][i]);

            del[ch][i]+=pos;
        }
    }

    forn(ch, 26){
        sort(del[ch], del[ch]+delcnt[ch]);

        int cnt=0;
        int j=0;
        forn(i, len)
            if(str[i]==ch+'a'){
                ++cnt;
                if(del[ch][j]==cnt){
                    str[i]=0;
                    ++j;
                }
            }
    }

    forn(i, len){
        if(str[i]!=0) printf("%c", str[i]);
    }

    return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <cmath>
#include <sstream>
#include <ctime>
#include <memory.h>
#define forn(i,n) for (int i = 0; i < (int)(n); i++)
#define forv(i, a) for(int i=0; i<(int)a.size(); i++)
#define mset(a, val) memset(a, val, sizeof(a))
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define VI vector< int >
#define VS vector< string >
#define PII pair< int,int >
#define PDD pair< double,double >
#define PIS pair< int, string >
#define sqr(a) ((a)*(a))
#define cube(a) ((a)*(a)*(a))
#define pi 3.1415926535897932384626433832795
#define PI pi
#define iinf 1000000000
#define sinf 10000
#define eps 1e-12
#define lng long long
#define X first
#define Y second
using namespace std;
#define prev asdprev
#define exit(a) { if (a) cerr<<"oops "<<a<<endl; exit(a); }

#define max(a, b) ((a>b)?a:b)

int segtree[800000];
int len;

void add(int val, int l, int r=len, int i=1, int tl=0, int tr=len){
    if(l==tl && r==tr) {
        segtree[i]+=val;
        return;
    }

    int tc=(tl+tr)/2;

    if(r<=tc) add(val, l, r, i*2, tl, tc);
    else if(l>tc) add(val, l, r, i*2+1, tc+1, tr);
    else{
        add(val, l, tc, i*2, tl, tc);
        add(val, tc+1, r, i*2+1, tc+1, tr);
    }
}

int get(int pos, int i=1, int tl=0, int tr=len){
    if(tl==tr && tl==pos) return segtree[i];

    int tc=(tl+tr)/2;
    int ans=0;

    if(pos<=tc) ans=get(pos, i*2, tl, tc);
    else ans=get(pos, i*2+1, tc+1, tr);

    return ans+segtree[i];
}

char str[300000];
int del[26][20000];
int delcnt[26];

#define taska "intersection"
int main() {
#ifdef __ASD__
    freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#else
    //freopen(taska".in", "r", stdin);freopen(taska".out", "w", stdout); freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#endif

    int n, k;
    string s;
    cin>>k;
    cin>>s;

    len=(int)s.size();
    forn(i, k){
        forv(j, s)
            str[i*len+j]=s[j];
    }

    len*=k;

    cin>>n;
    forn(i, n){
        int p;
        char c;

        cin>>p>>c;

        del[c-'a'][delcnt[c-'a']++]=p;
    }

    forn(ch, 26){
        mset(segtree, 0);

        forn(i, delcnt[ch]){
            int pos=get(del[ch][i]);

            add(1, del[ch][i]);

            del[ch][i]+=pos;
        }
    }

    forn(ch, 26){
        sort(del[ch], del[ch]+delcnt[ch]);

        int cnt=0;
        int j=0;
        forn(i, len)
            if(str[i]==ch+'a'){
                ++cnt;
                if(del[ch][j]==cnt){
                    str[i]=0;
                    ++j;
                }
            }
    }

    forn(i, len){
        if(str[i]!=0) printf("%c", str[i]);
    }

    return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <cmath>
#include <sstream>
#include <ctime>
#include <memory.h>
#define forn(i,n) for (int i = 0; i < (int)(n); i++)
#define forv(i, a) for(int i=0; i<(int)a.size(); i++)
#define mset(a, val) memset(a, val, sizeof(a))
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define VI vector< int >
#define VS vector< string >
#define PII pair< int,int >
#define PDD pair< double,double >
#define PIS pair< int, string >
#define sqr(a) ((a)*(a))
#define cube(a) ((a)*(a)*(a))
#define pi 3.1415926535897932384626433832795
#define PI pi
#define iinf 1000000000
#define sinf 10000
#define eps 1e-12
#define lng long long
#define X first
#define Y second
using namespace std;
#define prev asdprev
#define exit(a) { if (a) cerr<<"oops "<<a<<endl; exit(a); }

#define max(a, b) ((a>b)?a:b)

int segtree[800000];
int len;

void build(int i=1, int tl=1, int tr=len){
    if(tl==tr) segtree[i]=1;
    else{
        int tc=(tl+tr)/2;

        build(i*2, tl, tc);
        build(i*2+1, tc+1, tr);

        segtree[i]=segtree[i*2]+segtree[i*2+1];
    }
}

void setnul(int pos, int i=1, int tl=1, int tr=len){
    if(tl==tr && tl==pos){
        segtree[i]=0;
        return;
    }

    int tc=(tl+tr)/2;

    if(pos<=tc) setnul(pos, i*2, tl, tc);
    else setnul(pos, i*2+1, tc+1, tr);
    segtree[i]=segtree[i*2]+segtree[i*2+1];
}

int get(int r, int l=1, int i=1, int tl=1, int tr=len){
    if(tl==l && tr==r) return segtree[i];

    int tc=(tl+tr)/2;
    if(r<=tc) return get(r, l, i*2, tl, tc);
    else if(l>tc) return get(r, l,  i*2+1, tc+1, tr);
    else{
        return get(tc, l,  i*2, tl, tc) + get(r, tc+1,  i*2+1, tc+1, tr);
    }
}

int findit(int x){
    int b=1, e=len;

    while(b<e){
        int m=(b+e)/2;

        int cur=get(m);
        if(cur==x) e=m;
        else if(cur<x) b=m+1;
        else e=m-1;
    }
    return b;
}

char str[300000];
int del[26][20000];
int delcnt[26];
bool deleted[20700];

#define taska "intersection"
int main() {
#ifdef __ASD__
    freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#else
    //freopen(taska".in", "r", stdin);freopen(taska".out", "w", stdout); freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#endif

    int n, k;
    string s;
    cin>>k;
    cin>>s;

    len=(int)s.size();
    forn(i, k){
        forv(j, s)
            str[i*len+j]=s[j];
    }

    len*=k;

    cin>>n;
    forn(i, n){
        int p;
        char c;

        cin>>p>>c;

        del[c-'a'][delcnt[c-'a']++]=p;
    }

    forn(ch, 26){
        build();
        mset(deleted, 0);

        forn(i, delcnt[ch]){
            int pos=findit(del[ch][i]);
            del[ch][i]=pos;

            setnul(pos);
            deleted[pos]=true;
        }

        int cnt=0;
        if(delcnt[ch]>0)
        forn(i, len)
            if(str[i]==ch+'a'){
                ++cnt;
                if(deleted[cnt]) str[i]='!';
            }

    }

    forn(i, len)
        if(str[i]!='!') printf("%c", str[i]);

    return 0;
}


#include <iostream>
#include <string>
#include <vector>

using namespace std;

bool checked[200005];
vector<int> occ[26];

int main()
{
	int K, N;
	string os, s = "";

	cin >> K >> os >> N;
	for (int i = 0; i < K; i++)
		s += os;
	for (int i = 0; i < s.size(); i++)
		occ[((int) s[i])-97].push_back(i);
	for (int i = 0; i < N; i++) {
		int oc, in;
		char c;
		cin >> oc >> c;
		in = ((int) c);
		checked[occ[in-97][oc-1]] = 1;
		occ[in-97].erase(occ[in-97].begin()+oc-1);
	}
	for (int i = 0; i < s.size(); i++)
		if (!checked[i]) cout << s[i];
	cout << endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

struct letter{
    int pos;
    int simb;
};

bool cmp(letter a, letter b)
{
    return a.pos<b.pos;
}

int main(){
    int K,c,pos=1,col,n,p,cnt;
    char t;
    cin>>K;
    string s;
    cin>>s;
    vector<vector<vector<int> > > mas(26,vector<vector<int> >(501,vector<int>(501,0)));
    vector<int> column(26,0);

    for(int i=0;i<K;++i)
    {
        for(int j=0;j<s.size();++j)
        {
            c=s[j]-97;

            if(mas[c][column[c]][0]==500)
                column[c]++;

            mas[c][column[c]][0]++;
            mas[c][column[c]][mas[c][column[c]][0]]=pos;
            pos++;
        }
    }

    cin>>n;
    for(int i=0;i<n;++i)
    {
        cin>>p>>t;
        c=int(t)-97;
        cnt=0;
        for(col=0;col<501;++col)
                if(cnt+mas[c][col][0]>=p)
                    break;
                else
                    cnt+=mas[c][col][0];

        p-=cnt;
        mas[c][col][0]--;

        for(int j=1;j<501;++j)
        {
            if(mas[c][col][j]!=-1)
                p--;

            if(p==0)
            {
                mas[c][col][j]=-1;
                break;
            }
        }
    }

    letter simb;
    vector<letter> res;
    for(int i=0;i<26;++i)
    {
        simb.simb=i;
        for(int j=0;j<501;++j)
        {
            if(mas[i][j][0]==0)
                continue;

            for(int k=1;k<501;++k)
            {
                if(mas[i][j][k]>0)
                {
                    simb.pos=mas[i][j][k];
                    res.push_back(simb);
                }
            }
        }
    }

    sort(res.begin(),res.end(),cmp);

    for(int i=0;i<res.size();++i)
        cout<<char(res[i].simb+97);

return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

struct letter{
    int pos;
    int simb;
};

bool cmp(letter a, letter b)
{
    return a.pos<b.pos;
}

int main3(){
    int K,c,pos=1,col,n,p,cnt;
    char t;
    cin>>K;
    string s;
    cin>>s;
    vector<vector<vector<int> > > mas(26,vector<vector<int> >(501,vector<int>(501,0)));
    vector<int> column(26,0);

    for(int i=0;i<K;++i)
    {
        for(int j=0;j<s.size();++j)
        {
            c=s[j]-97;

            if(mas[c][column[c]][0]==500)
                column[c]++;

            mas[c][column[c]][0]++;
            mas[c][column[c]][mas[c][column[c]][0]]=pos;
            pos++;
        }
    }

    cin>>n;
    for(int i=0;i<n;++i)
    {
        cin>>p>>t;
        c=int(t)-97;
        cnt=0;
        for(col=0;col<501;++col)
                if(cnt+mas[c][col][0]>=p)
                    break;
                else
                    cnt+=mas[c][col][0];

        p-=cnt;
        mas[c][col][0]--;

        for(int j=1;j<501;++j)
        {
            if(mas[c][col][j]!=-1)
                p--;

            if(p==0)
            {
                mas[c][col][j]=-1;
                break;
            }
        }
    }

    letter simb;
    vector<letter> res;
    for(int i=0;i<26;++i)
    {
        simb.simb=i;
        for(int j=0;j<501;++j)
        {
            if(mas[i][j][0]==0)
                continue;

            for(int k=1;k<501;++k)
            {
                if(mas[i][j][k]>0)
                {
                    simb.pos=mas[i][j][k];
                    res.push_back(simb);
                }
            }
        }
    }

    sort(res.begin(),res.end(),cmp);

    for(int i=0;i<res.size();++i)
        cout<<char(res[i].simb+97);

return 0;
}


/* prog: String Manipulation
 * auth: linh810
 * lang: C++
 * cons: VK Cup Qualification Round 2
 */

#include <iostream>
#include <string>
#include <vector>

#define LIM 200001

using namespace std;

int k, n, m;
string s;
vector <int> query[26];
int basic[26], bi[30][200200];
bool app[2020][111];

int calc(int t, int u) {
	int temp = 0;
	while (u > 0) {
		temp += bi[t][u];
		u -= u & (-u);
	}
	return temp;
}

void update(int t, int u) {
	while (u < LIM) {
		bi[t][u]++;
		u += u & (-u);
	}
}

void del(int u, int t, int p) {
	char c = u + 'a';
	for (int i = 0; i < m; i++) {
		if (s[i] == c)
			p--;
		if (p < 0) {
			app[t][i] = false;
			return;
		}
	}
}

void process(int u) {
	if (basic[u] == 0)
		return;
	for (int i = 0; i < query[u].size(); i++) {
		int occur = query[u][i] + calc(u, query[u][i]) - 1;
		update(u, query[u][i]);
		del(u, occur / basic[u], occur % basic[u]);
	}
}

int main() {
	memset(app, true, sizeof app);
	cin >> k >> s >> n;
	m = s.length();
	for (int i = 0; i < s.length(); i++)
		basic[s[i] - 'a']++;
	for (int i = 0; i < n; i++) {
		int p; string c;
		cin >> p >> c;
		query[c[0] - 'a'].push_back(p);
	}
	for (int i = 0; i < 26; i++)
		process(i);
	for (int u = 0; u < k; u++) {
		for (int i = 0; i < m; i++)
			if (app[u][i])
				printf("%c", s[i]);
	}
}


/* prog: String Manipulation
 * auth: linh810
 * lang: C++
 * cons: VK Cup Qualification Round 2
 */

#include <iostream>
#include <string>
#include <vector>

#define LIM 200001

using namespace std;

int k, n, m;
string s;
vector <int> query[26];
int basic[26], bi[30][200200];
bool app[2020][111];
bool state[26][200200];

int calc(int t, int u) {
	int temp = 0;
	while (u > 0) {
		temp += bi[t][u];
		u -= u & (-u);
	}
	return temp;
}

void update(int t, int u) {
	while (u < LIM) {
		bi[t][u]++;
		u += u & (-u);
	}
}

void del(int u, int t, int p) {
	char c = u + 'a';
	for (int i = 0; i < m; i++) {
		if (s[i] == c)
			p--;
		if (p < 0) {
			app[t][i] = false;
			return;
		}
	}
}

int find(int u, int p) {
	int lo = 0, hi = 1;
	while (hi - calc(u, hi) < p) hi *= 2;
	while (!state[u][hi]) hi++;
	while (hi - lo > 1) {
		int mi = (hi + lo) / 2;
		if (mi - calc(u, mi) == p)
			return mi;
		if (mi - calc(u, mi) < p)
			lo = mi;
		else {
			hi = mi;
			while (!state[u][hi]) hi++;
		}
	}
	if (hi - calc(u, hi) == p)
		return hi;
	if (lo - calc(u, lo) == p)
		return lo;
}

void process(int u) {
	if (basic[u] == 0)
		return;
	for (int i = 0; i < query[u].size(); i++) {
		int occur = find(u, query[u][i]);
		update(u, occur);
		state[u][occur] = false;
		occur--;
		del(u, occur / basic[u], occur % basic[u]);
	}
}

int main() {
	memset(state, true, sizeof state);
	memset(app, true, sizeof app);
	cin >> k >> s >> n;
	m = s.length();
	for (int i = 0; i < m; i++)
		basic[s[i] - 'a']++;
	for (int i = 0; i < n; i++) {
		int p; string c;
		cin >> p >> c;
		query[c[0] - 'a'].push_back(p);
	}
	for (int i = 0; i < 26; i++)
		process(i);
	for (int u = 0; u < k; u++) {
		for (int i = 0; i < m; i++)
			if (app[u][i])
				printf("%c", s[i]);
	}
}


/* prog: String Manipulation
 * auth: linh810
 * lang: C++
 * cons: VK Cup Qualification Round 2
 */

#include <iostream>
#include <string>
#include <vector>

#define LIM 200001

using namespace std;

int k, n, m;
string s;
vector <int> query[26];
int basic[26], bi[30][200200];
bool app[2020][111];

int calc(int t, int u) {
	int temp = 0;
	while (u > 0) {
		temp += bi[t][u];
		u -= u & (-u);
	}
	return temp;
}

void update(int t, int u) {
	while (u < LIM) {
		bi[t][u]++;
		u += u & (-u);
	}
}

void del(int u, int t, int p) {
	char c = u + 'a';
	for (int i = 0; i < m; i++) {
		if (s[i] == c)
			p--;
		if (p < 0) {
			app[t][i] = false;
			return;
		}
	}
}

void process(int u) {
	if (basic[u] == 0)
		return;
	for (int i = 0; i < query[u].size(); i++) {
		int occur = query[u][i] + calc(u, query[u][i]) - 1;
		update(u, occur + 1);
		del(u, occur / basic[u], occur % basic[u]);
	}
}

int main() {
	memset(app, true, sizeof app);
	cin >> k >> s >> n;
	m = s.length();
	for (int i = 0; i < s.length(); i++)
		basic[s[i] - 'a']++;
	for (int i = 0; i < n; i++) {
		int p; string c;
		cin >> p >> c;
		query[c[0] - 'a'].push_back(p);
	}
	for (int i = 0; i < 26; i++)
		process(i);
	for (int u = 0; u < k; u++) {
		for (int i = 0; i < m; i++)
			if (app[u][i])
				printf("%c", s[i]);
	}
}


/* prog: String Manipulation
 * auth: linh810
 * lang: C++
 * cons: VK Cup Qualification Round 2
 */

#include <iostream>
#include <string>
#include <vector>

#define LIM 200001

using namespace std;

int k, n, m;
string s;
vector <int> query[26];
int basic[26], bi[30][200200];
bool app[2020][111];
int position[26][111];

int calc(int t, int u) {
	int temp = 0;
	while (u > 0) {
		temp += bi[t][u];
		u -= u & (-u);
	}
	return temp;
}

void update(int t, int u) {
	while (u < LIM) {
		bi[t][u]++;
		u += u & (-u);
	}
}

void del(int u, int t, int p) {
	app[t][position[u][p]] = false;
}

int find(int u, int p) {
	int lo = 0, hi = 1;
	while (hi - calc(u, hi) < p) hi *= 2;
	while (hi - lo > 1) {
		int mi = (hi + lo) / 2;
		if (mi - calc(u, mi) < p)
			lo = mi;
		else
			hi = mi;
	}
	return hi;
}

void process(int u) {
	for (int i = 0; i < query[u].size(); i++) {
		int occur = find(u, query[u][i]);
		update(u, occur);
		occur--;
		del(u, occur / basic[u], occur % basic[u]);
	}
}

int main() {
	memset(app, true, sizeof app);
	cin >> k >> s >> n;
	m = s.length();
	for (int i = 0; i < m; i++) {
		position[s[i] - 'a'][basic[s[i] - 'a']] = i;
		basic[s[i] - 'a']++;
	}
	for (int i = 0; i < n; i++) {
		int p; string c;
		cin >> p >> c;
		query[c[0] - 'a'].push_back(p);
	}
	for (int i = 0; i < 26; i++)
		process(i);
	for (int u = 0; u < k; u++) {
		for (int i = 0; i < m; i++)
			if (app[u][i])
				printf("%c", s[i]);
	}
}


/* prog: String Manipulation
 * auth: linh810
 * lang: C++
 * cons: VK Cup Qualification Round 2
 */

#include <iostream>
#include <string>
#include <vector>

#define LIM 200001

using namespace std;

int k, n, m;
string s;
vector <int> query[26];
int basic[26], bi[30][200200];
bool app[2020][111];

int calc(int t, int u) {
	int temp = 0;
	while (u > 0) {
		temp += bi[t][u];
		u -= u & (-u);
	}
	return temp;
}

void update(int t, int u) {
	while (u < LIM) {
		bi[t][u]++;
		u += u & (-u);
	}
}

void del(int u, int t, int p) {
	char c = u + 'a';
	for (int i = 0; i < m; i++) {
		if (s[i] == c)
			p--;
		if (p < 0) {
			app[t][i] = false;
			return;
		}
	}
}

int find(int u, int p) {
	int lo = 0, hi = 1;
	while (hi - calc(u, hi - 1) < p) hi *= 2;
	while (hi - lo > 1) {
		int mi = (hi + lo) / 2;
		if (mi - calc(u, mi - 1) == p)
			return mi;
		if (mi - calc(u, mi - 1) < p)
			lo = mi;
		else
			hi = mi;
	}
	if (hi - calc(u, hi - 1) == p)
		return hi;
	if (lo - calc(u, lo - 1) == p)
		return lo;
}

void process(int u) {
	if (basic[u] == 0)
		return;
	for (int i = 0; i < query[u].size(); i++) {
		int occur = find(u, query[u][i]);
		update(u, occur);
		occur--;
		del(u, occur / basic[u], occur % basic[u]);
	}
}

int main() {
	memset(app, true, sizeof app);
	cin >> k >> s >> n;
	m = s.length();
	for (int i = 0; i < m; i++)
		basic[s[i] - 'a']++;
	for (int i = 0; i < n; i++) {
		int p; string c;
		cin >> p >> c;
		query[c[0] - 'a'].push_back(p);
	}
	for (int i = 0; i < 26; i++)
		process(i);
	for (int u = 0; u < k; u++) {
		for (int i = 0; i < m; i++)
			if (app[u][i])
				printf("%c", s[i]);
	}
}


/* prog: String Manipulation
 * auth: linh810
 * lang: C++
 * cons: VK Cup Qualification Round 2
 */

#include <iostream>
#include <string>
#include <vector>

#define LIM 200001

using namespace std;

int k, n, m;
string s;
vector <int> query[26];
int basic[26], bi[30][200200];
bool app[2020][111];

int calc(int t, int u) {
	int temp = 0;
	while (u > 0) {
		temp += bi[t][u];
		u -= u & (-u);
	}
	return temp;
}

void update(int t, int u) {
	while (u < LIM) {
		bi[t][u]++;
		u += u & (-u);
	}
}

void del(int u, int t, int p) {
	char c = u + 'a';
	for (int i = 0; i < m; i++) {
		if (s[i] == c)
			p--;
		if (p < 0) {
			app[t][i] = false;
			return;
		}
	}
}

void process(int u) {
	if (basic[u] == 0)
		return;
	for (int i = 0; i < query[u].size(); i++) {
		int occur = query[u][i] + calc(u, query[u][i]) - 1;
		update(u, occur);
		del(u, occur / basic[u], occur % basic[u]);
	}
}

int main() {
	memset(app, true, sizeof app);
	cin >> k >> s >> n;
	m = s.length();
	for (int i = 0; i < s.length(); i++)
		basic[s[i] - 'a']++;
	for (int i = 0; i < n; i++) {
		int p; string c;
		cin >> p >> c;
		query[c[0] - 'a'].push_back(p);
	}
	for (int i = 0; i < 26; i++)
		process(i);
	for (int u = 0; u < k; u++) {
		for (int i = 0; i < m; i++)
			if (app[u][i])
				printf("%c", s[i]);
	}
}


/* prog: String Manipulation
 * auth: linh810
 * lang: C++
 * cons: VK Cup Qualification Round 2
 */

#include <iostream>
#include <string>
#include <vector>

#define LIM 200001

using namespace std;

int k, n, m;
string s;
vector <int> query[26];
int basic[26], bi[30][200200];
bool app[2020][111];
int position[26][111];

int calc(int t, int u) {
	int temp = 0;
	while (u > 0) {
		temp += bi[t][u];
		u -= u & (-u);
	}
	return temp;
}

void update(int t, int u) {
	while (u < LIM) {
		bi[t][u]++;
		u += u & (-u);
	}
}

void del(int u, int t, int p) {
	app[t][position[u][p]] = false;
}

int find(int u, int p) {
	int lo = 0, hi = 1;
	while (hi - calc(u, hi) < p) hi *= 2;
	while (hi - lo > 1) {
		int mi = (hi + lo) / 2;
		if (mi - calc(u, mi) < p)
			lo = mi;
		else
			hi = mi;
	}
	return hi;
}

void process(int u) {
	for (int i = 0; i < query[u].size(); i++) {
		int occur = find(u, query[u][i]);
		update(u, occur);
		occur--;
		del(u, occur / basic[u], occur % basic[u]);
	}
}

int main() {
	memset(app, true, sizeof app);
	cin >> k >> s >> n;
	m = s.length();
	for (int i = 0; i < m; i++) {
		basic[s[i] - 'a']++;
		position[s[i] - 'a'][basic[s[i] - 'a']] = i;
	}
	for (int i = 0; i < n; i++) {
		int p; string c;
		cin >> p >> c;
		query[c[0] - 'a'].push_back(p);
	}
	for (int i = 0; i < 26; i++)
		process(i);
	for (int u = 0; u < k; u++) {
		for (int i = 0; i < m; i++)
			if (app[u][i])
				printf("%c", s[i]);
	}
}


/* prog: String Manipulation
 * auth: linh810
 * lang: C++
 * cons: VK Cup Qualification Round 2
 */

#include <iostream>
#include <string>
#include <vector>

#define LIM 200001

using namespace std;

int k, n, m;
string s;
vector <int> query[26];
int basic[26], bi[30][200200];
bool app[2020][111];
bool state[26][200200];

int calc(int t, int u) {
	int temp = 0;
	while (u > 0) {
		temp += bi[t][u];
		u -= u & (-u);
	}
	return temp;
}

void update(int t, int u) {
	while (u < LIM) {
		bi[t][u]++;
		u += u & (-u);
	}
}

void del(int u, int t, int p) {
	char c = u + 'a';
	for (int i = 0; i < m; i++) {
		if (s[i] == c)
			p--;
		if (p < 0) {
			app[t][i] = false;
			return;
		}
	}
}

int find(int u, int p) {
	int lo = 0, hi = 1;
	while (hi - calc(u, hi) < p) hi *= 2;
	while (!state[u][hi]) hi++;
	while (hi - lo > 1) {
		int mi = (hi + lo) / 2;
		if (mi - calc(u, mi) < p)
			lo = mi;
		else {
			hi = mi;
			while (!state[u][hi]) hi++;
		}
	}
	if (hi - calc(u, hi) == p)
		return hi;
	if (lo - calc(u, lo) == p)
		return lo;
}

void process(int u) {
	if (basic[u] == 0)
		return;
	for (int i = 0; i < query[u].size(); i++) {
		int occur = find(u, query[u][i]);
		update(u, occur);
		state[u][occur] = false;
		occur--;
		del(u, occur / basic[u], occur % basic[u]);
	}
}

int main() {
	memset(state, true, sizeof state);
	memset(app, true, sizeof app);
	cin >> k >> s >> n;
	m = s.length();
	for (int i = 0; i < m; i++)
		basic[s[i] - 'a']++;
	for (int i = 0; i < n; i++) {
		int p; string c;
		cin >> p >> c;
		query[c[0] - 'a'].push_back(p);
	}
	for (int i = 0; i < 26; i++)
		process(i);
	for (int u = 0; u < k; u++) {
		for (int i = 0; i < m; i++)
			if (app[u][i])
				printf("%c", s[i]);
	}
}


/* prog: String Manipulation
 * auth: linh810
 * lang: C++
 * cons: VK Cup Qualification Round 2
 */

#include <iostream>
#include <string>
#include <vector>

#define LIM 200001

using namespace std;

int k, n, m;
string s;
vector <int> query[26];
int basic[26], bi[30][200200];
bool app[2020][111];

int calc(int t, int u) {
	int temp = 0;
	while (u > 0) {
		temp += bi[t][u];
		u -= u & (-u);
	}
	return temp;
}

void update(int t, int u) {
	while (u < LIM) {
		bi[t][u]++;
		u += u & (-u);
	}
}

void del(int u, int t, int p) {
	char c = u + 'a';
	for (int i = 0; i < m; i++) {
		if (s[i] == c)
			p--;
		if (p < 0) {
			app[t][i] = false;
			return;
		}
	}
}

int find(int u, int p) {
	int lo = 0, hi = 1;
	while (hi - calc(u, hi) < p) hi *= 2;
	while (hi - lo > 1) {
		int mi = (hi + lo) / 2;
		if (mi - calc(u, mi) < p)
			lo = mi;
		else
			hi = mi;
	}
	return hi;
}

void process(int u) {
	for (int i = 0; i < query[u].size(); i++) {
		int occur = find(u, query[u][i]);
		update(u, occur);
		occur--;
		del(u, occur / basic[u], occur % basic[u]);
	}
}

int main() {
	memset(state, true, sizeof state);
	memset(app, true, sizeof app);
	cin >> k >> s >> n;
	m = s.length();
	for (int i = 0; i < m; i++)
		basic[s[i] - 'a']++;
	for (int i = 0; i < n; i++) {
		int p; string c;
		cin >> p >> c;
		query[c[0] - 'a'].push_back(p);
	}
	for (int i = 0; i < 26; i++)
		process(i);
	for (int u = 0; u < k; u++) {
		for (int i = 0; i < m; i++)
			if (app[u][i])
				printf("%c", s[i]);
	}
}


/* prog: String Manipulation
 * auth: linh810
 * lang: C++
 * cons: VK Cup Qualification Round 2
 */

#include <iostream>
#include <string>
#include <vector>

#define LIM 200001

using namespace std;

int k, n, m;
string s;
vector <int> query[26];
int basic[26], bi[30][200200];
bool app[2020][111];

int calc(int t, int u) {
	int temp = 0;
	while (u > 0) {
		temp += bi[t][u];
		u -= u & (-u);
	}
	return temp;
}

void update(int t, int u) {
	while (u < LIM) {
		bi[t][u]++;
		u += u & (-u);
	}
}

void del(int u, int t, int p) {
	char c = u + 'a';
	for (int i = 0; i < m; i++) {
		if (s[i] == c)
			p--;
		if (p < 0) {
			app[t][i] = false;
			return;
		}
	}
}

int find(int u, int p) {
	int lo = 0, hi = 1;
	while (hi - calc(u, hi) < p) hi *= 2;
	while (hi - lo > 1) {
		int mi = (hi + lo) / 2;
		if (mi - calc(u, mi) == p)
			return mi;
		if (mi - calc(u, mi) < p)
			lo = mi;
		else
			hi = mi;
	}
	if (hi - calc(u, hi) == p)
		return hi;
	if (lo - calc(u, lo) == p)
		return lo;
}

void process(int u) {
	if (basic[u] == 0)
		return;
	for (int i = 0; i < query[u].size(); i++) {
		int occur = find(u, query[u][i]);
		update(u, occur);
		occur--;
		del(u, occur / basic[u], occur % basic[u]);
	}
}

int main() {
	memset(app, true, sizeof app);
	cin >> k >> s >> n;
	m = s.length();
	for (int i = 0; i < s.length(); i++)
		basic[s[i] - 'a']++;
	for (int i = 0; i < n; i++) {
		int p; string c;
		cin >> p >> c;
		query[c[0] - 'a'].push_back(p);
	}
	for (int i = 0; i < 26; i++)
		process(i);
	for (int u = 0; u < k; u++) {
		for (int i = 0; i < m; i++)
			if (app[u][i])
				printf("%c", s[i]);
	}
}


/* prog: String Manipulation
 * auth: linh810
 * lang: C++
 * cons: VK Cup Qualification Round 2
 */

#include <iostream>
#include <string>
#include <vector>

#define LIM 200001

using namespace std;

int k, n, m;
string s;
vector <string> e;
vector <int> query[26];
int basic[26], bi[30][200200];
bool app[2020][111];

int calc(int t, int u) {
	int temp = 0;
	while (u > 0) {
		temp += bi[t][u];
		u -= u & (-u);
	}
	return temp;
}

void update(int t, int u) {
	while (u < LIM) {
		bi[t][u]++;
		u += u & (-u);
	}
}

void del(int u, int t, int p) {
	char c = u + 'a';
	for (int i = 0; i < m; i++) {
		if (s[i] == c)
			p--;
		if (p < 0) {
			app[t][i] = false;
			return;
		}
	}
}

void process(int u) {
	for (int i = 0; i < query[u].size(); i++) {
		int occur = query[u][i] + calc(u, query[u][i]) - 1;
		update(u, query[u][i]);
		del(u, occur / basic[u], occur % basic[u]);
	}
}

int main() {
	memset(app, true, sizeof app);
	cin >> k >> s >> n;
	m = s.length();
	for (int i = 0; i < s.length(); i++)
		basic[s[i] - 'a']++;
	e.resize(k, s);
	for (int i = 0; i < n; i++) {
		int p; string c;
		cin >> p >> c;
		query[c[0] - 'a'].push_back(p);
	}
	for (int i = 0; i < 26; i++)
		process(i);
	for (int u = 0; u < k; u++) {
		for (int i = 0; i < m; i++)
			if (app[u][i])
				printf("%c", s[i]);
	}
}


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

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)((x).size()))
#define sqr(x) ((x)*(x))
#define For(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) For(i,0,n)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define re return
#define fi first
#define se second
#define y0 y47847892
#define y1 y47824262
#define fill(x, val) memset(x, val, sizeof(x))
#define max(a,b) ((a)>=(b)?(a):(b))
#define min(a,b) ((a)<=(b)?(a):(b))

using namespace std;

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;

#pragma comment(linker, "/STACK:16777216")

template<class T> T abs(T x) { return x > 0 ? x : -x;}

int n;
int k;

int main() {
	string s[2010];
	int stat[2010][125];
	string s0;
	int stat0[125];

	cin >> k >> s0 >> n;
	rep(j, 125)
	{
		stat0[j] = 0;
	}
	rep(j, s0.length())
		stat0[s0[j]]++;

	rep(i, k)
	{
		s[i] = s0;
		rep(j, 125)
		{
			stat[i][j] = stat0[j]*(i+1);
		}
	}

	rep(i, n)
	{
		int ind;
		char ch;
		cin >> ind >> ch;
		int ask = stat0[ch]; // del
		int nom = (ind-1) / stat0[ch];
		while (stat[nom][ch] < ind)
			nom++;
		if (nom > 0)
			ind -= stat[nom-1][ch];

		int j=0;
		while (ind > 0)
		{
			j = s[nom].find(ch, j) + 1;
			ind--;
		}
		j--;
		s[nom].erase(j,1);
		For(j,nom,k)
			stat[j][ch]--;
	}

	rep(i,k)
		cout << s[i];
	return 0;
}


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

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)((x).size()))
#define sqr(x) ((x)*(x))
#define For(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) For(i,0,n)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define re return
#define fi first
#define se second
#define y0 y47847892
#define y1 y47824262
#define fill(x, val) memset(x, val, sizeof(x))
#define max(a,b) ((a)>=(b)?(a):(b))
#define min(a,b) ((a)<=(b)?(a):(b))

using namespace std;

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;

#pragma comment(linker, "/STACK:16777216")

template<class T> T abs(T x) { return x > 0 ? x : -x;}

int n;
int k;

int main() {
	string s[2000];
	char stat[2000][123];
	string s0;
	char stat0[123];

	cin >> k >> s0 >> n;
	rep(j, 123)
	{
		stat0[j] = 0;
	}
	rep(j, s0.length())
		stat0[s0[j]]++;

	rep(i, k)
	{
		s[i] = s0;
		For(j, 97, 123)
		{
			stat[i][j] = stat0[j]*(i+1);
		}
	}

	rep(i, n)
	{
		int ind;
		char ch;
		cin >> ind >> ch;
		int ask = stat0[ch]; // del
		int nom = (ind-1) / stat0[ch];
		while (stat[nom][ch] < ind)
			nom++;
		if (nom > 0)
			ind -= stat[nom-1][ch];

		int j=0;
		while (ind > 0)
		{
			j = s[nom].find(ch, j) + 1;
			ind--;
		}
		j--;
		s[nom].erase(j,1);
		For(j,nom,k)
			stat[j][ch]--;
	}

	rep(i,n)
		cout << s[i];
	return 0;
}


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

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)((x).size()))
#define sqr(x) ((x)*(x))
#define For(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) For(i,0,n)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define re return
#define fi first
#define se second
#define y0 y47847892
#define y1 y47824262
#define fill(x, val) memset(x, val, sizeof(x))
#define max(a,b) ((a)>=(b)?(a):(b))
#define min(a,b) ((a)<=(b)?(a):(b))

using namespace std;

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;

#pragma comment(linker, "/STACK:16777216")

template<class T> T abs(T x) { return x > 0 ? x : -x;}

int n;
int k;

int main() {
	string s[2010];
	char stat[2010][125];
	string s0;
	char stat0[125];

	cin >> k >> s0 >> n;
	rep(j, 125)
	{
		stat0[j] = 0;
	}
	rep(j, s0.length())
		stat0[s0[j]]++;

	rep(i, k)
	{
		s[i] = s0;
		rep(j, 125)
		{
			stat[i][j] = stat0[j]*(i+1);
		}
	}

	rep(i, n)
	{
		int ind;
		char ch;
		cin >> ind >> ch;
		int ask = stat0[ch]; // del
		int nom = (ind-1) / stat0[ch];
		while (stat[nom][ch] < ind)
			nom++;
		if (nom > 0)
			ind -= stat[nom-1][ch];

		int j=0;
		while (ind > 0)
		{
			j = s[nom].find(ch, j) + 1;
			ind--;
		}
		j--;
		s[nom].erase(j,1);
		For(j,nom,k)
			stat[j][ch]--;
	}

	rep(i,k)
		cout << s[i];
	return 0;
}


#include <iostream>
#include <algorithm>
#include <fstream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <iomanip>

using namespace std;

#define rep(i,o,n) for (int i=o;i<=n;i++)
#define rd cin >>
#define w cout <<
#define wl cout << endl
#define road pair<int,int>
//#define cin inf
//#define cout of
#define ll long long

int a[30][30000];

int main()
{
	ifstream inf("input.txt");
	pair<int,char> p[30000];
	int c[30]={0},n,b[30]={0},k;
	rd k;
	string s;
	rd s;
	int l = s.size();
	rd n;
	rep(i,1,n)
	{
		int x; char y;
		rd x >> y;
		int h = y-96;
		int j = upper_bound(a[h]+1,a[h]+c[h]+1,x)-a[h];
		for (int i1 = c[h]; i1>=j; i1--)
			a[h][i1+1] = a[h][i1];
		a[h][j] = j+x-1;
		c[h]++;
	}
	rep(i,1,k)
		rep(i1,0,l-1)
		{
			b[s[i1]-96]++;
			int h = s[i1]-96;
			int j = lower_bound(a[h]+1,a[h]+c[h]+1,b[h])-a[h];
			if (j>c[h]) j--;
			if (a[h][j]!=b[h]) w s[i1];
		}
}


#include <iostream>
#include <algorithm>
#include <fstream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <iomanip>

using namespace std;

#define rep(i,o,n) for (int i=o;i<=n;i++)
#define rd cin >>
#define w cout <<
#define wl cout << endl
#define road pair<int,int>
//#define cin inf
//#define cout of
#define ll long long

int main()
{
	ifstream inf("input.txt");
	vector<int> a[30];
	pair<int,char> p[30000];
	int n,b[30]={0},k;
	rd k;
	string s;
	rd s;
	int l = s.size();
	rd n;
	rep(i,1,n)
		rd p[i].first >> p[i].second;
	sort(p+1,p+n+1);
	rep(i,1,n)
		a[p[i].second-96].push_back(a[p[i].second-96].size()+p[i].first);
	rep(i,1,k)
		rep(i1,0,l-1)
		{
			b[s[i1]-96]++;
			int j = lower_bound(a[s[i1]-96].begin(),a[s[i1]-96].end(),b[s[i1]-96])-a[s[i1]-96].begin();
			if (j==a[s[i1]-96].size()) j--;
			if (a[s[i1]-96][j]!=b[s[i1]-96]) w s[i1];
		}
}


#include <iostream>
#include <algorithm>
#include <fstream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <iomanip>

using namespace std;

#define rep(i,o,n) for (int i=o;i<=n;i++)
#define rd cin >>
#define w cout <<
#define wl cout << endl
#define road pair<int,int>
//#define cin inf
//#define cout of
#define ll long long

int main()
{
	ifstream inf("input.txt");
	vector<int> a[30];
	int n,b[30]={0},c[30]={0},k;
	rd k;
	string s;
	rd s;
	rd n;
	rep(i,1,n)
	{
		int x; char y;
		rd x >> y;
		int h = y-96,j=a[h].size(),l=a[h].size();
		rep(i1,0,l-1)
			if (x+i1<a[h][i1]) { j = i; break; }
		for (int i1 = l-1; i1>=j; i1--)
			if (i1==l-1) a[h].push_back(a[h][i1]); else a[h][i1+1] = a[h][i1];
		//w j;
		if (j==l) a[h].push_back(x+j); else a[h][j] = x+j;
	}
	int l = s.size();
	rep(i,1,k)
		rep(i1,0,l-1)
		{
			int h = s[i1]-96;
			c[h]++;
			if (b[h]<a[h].size() && a[h][b[h]]==c[h]) b[h]++; else w s[i1];
		}
}


#include <iostream>
#include <algorithm>
#include <fstream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <iomanip>

using namespace std;

#define rep(i,o,n) for (int i=o;i<=n;i++)
#define rd cin >>
#define w cout <<
#define wl cout << endl
#define road pair<int,int>
#define cin inf
//#define cout of
#define ll long long

int main()
{
	ifstream inf("input.txt");
	set<int> a[30];
	pair<int,char> p[30000];
	int n,b[30]={0},k;
	rd k;
	string s;
	rd s;
	int l = s.size();
	rd n;
	rep(i,1,n)
		rd p[i].first >> p[i].second;
	sort(p+1,p+n+1);
	rep(i,1,n)
		a[p[i].second-96].insert(a[p[i].second-96].size()+p[i].first);
	rep(i,1,k)
		rep(i1,0,l-1)
		{
			b[s[i1]-96]++;
			if (a[s[i1]-96].count(b[s[i1]-96])==0) w s[i1];
		}
}


#include <iostream>
#include <algorithm>
#include <fstream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <iomanip>

using namespace std;

#define rep(i,o,n) for (int i=o;i<=n;i++)
#define rd cin >>
#define w cout <<
#define wl cout << endl
#define road pair<int,int>
//#define cin inf
//#define cout of
#define ll long long

int main()
{
	ifstream inf("input.txt");
	vector<int> a[30];
	int n,b[30]={0},c[30]={0},k;
	rd k;
	string s;
	rd s;
	rd n;
	rep(i,1,n)
	{
		int x; char y;
		rd x >> y;
		int h = y-96,j=a[h].size(),l=a[h].size();
		rep(i1,0,l-1)
			if (x+i1<a[h][i1]) { j = i1; break; }
		for (int i1 = l-1; i1>=j; i1--)
			if (i1==l-1) a[h].push_back(a[h][i1]); else a[h][i1+1] = a[h][i1];
		//w j;
		if (j==l) a[h].push_back(x+j); else a[h][j] = x+j;
	}
	int l = s.size();
	rep(i,1,k)
		rep(i1,0,l-1)
		{
			int h = s[i1]-96;
			c[h]++;
			if (b[h]<a[h].size() && a[h][b[h]]==c[h]) b[h]++; else w s[i1];
		}
}


#include <iostream>
#include <algorithm>
#include <fstream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <iomanip>

using namespace std;

#define rep(i,o,n) for (int i=o;i<=n;i++)
#define rd cin >>
#define w cout <<
#define wl cout << endl
#define road pair<int,int>
//#define cin inf
//#define cout of
#define ll long long

int main()
{
	ifstream inf("input.txt");
	vector<int> a[30];
	int n,b[30]={0},c[30]={0},k;
	rd k;
	string s;
	rd s;
	int l = s.size();
	rep(i,0,l-1)
		c[s[i]-96]++;
	rd n;
	rep(i,1,n)
	{
		int x; char y;
		rd x >> y;
		a[y-96].push_back(upper_bound(a[y-96].begin(),a[y-96].end(),x)-a[y-96].begin()+x);
	}
	rep(i,1,k)
		rep(i1,0,l-1)
		{
			b[s[i1]-96]++;
			int j = lower_bound(a[s[i1]-96].begin(),a[s[i1]-96].end(),b[s[i1]-96])-a[s[i1]-96].begin();
			if (j==a[s[i1]-96].size()) j--;
			if (a[s[i1]-96][j]!=b[s[i1]-96]) w s[i1];
		}
}


#include <iostream>
#include <algorithm>
#include <fstream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <iomanip>

using namespace std;

#define rep(i,o,n) for (int i=o;i<=n;i++)
#define rd cin >>
#define w cout <<
#define wl cout << endl
#define road pair<int,int>
//#define cin inf
//#define cout of
#define ll long long

int main()
{
	ifstream inf("input.txt");
	set<int> a[30];
	pair<int,char> p[30000];
	int n,b[30]={0},k;
	rd k;
	string s;
	rd s;
	int l = s.size();
	rd n;
	rep(i,1,n)
		rd p[i].first >> p[i].second;
	sort(p+1,p+n+1);
	rep(i,1,n)
		a[p[i].second-96].insert(a[p[i].second-96].size()+p[i].first);
	rep(i,1,k)
		rep(i1,0,l-1)
		{
			b[s[i1]-96]++;
			if (a[s[i1]-96].count(b[s[i1]-96])==0) w s[i1];
		}
}


//#define MY 1

#pragma comment(linker, "/STACK:64000000")

#include <string>
#include <vector>
#include <set>
#include <queue>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <map>

#ifdef MY
#include <fstream>
using namespace std;
ifstream cin("input.txt");
ofstream cout("output.txt");
#else
#include <iostream>
using namespace std;
#endif

struct cmp{
	bool operator () (const pair<int, int> & a, const pair<int, int> & b){
		return (a.first < b.first);
	}
};

long long t[200005][30] = {}, n;

void inc(int pos, int c, int x){
	for(; pos < 200005; pos = pos | (pos + 1))
		t[pos][c] += x;
}

int get_all(int pos, int c){
	int ans = 0;
	for(; pos >= 0; pos = (pos & (pos + 1)) - 1)
		ans += t[pos][c];
	return ans;
}

int get(int l, int r, int c){
	return get_all(r, c) - get_all(l - 1, c);
}

int main(){
	long long k, x, y;
	string s;
	cin >> k >> s >> n;
	vector< pair<int, char> > p(n);
	vector< vector<int> > ans('z' - 'a' + 1);
	for(int i = 0; i < n; ++i){
		cin >> p[i].first >> p[i].second;
		x = get(1, p[i].first, p[i].second - 'a');
		y = x;
		x = get(1, p[i].first + x, p[i].second - 'a');
		while(x != y){
			y = x;
			x = get(1, p[i].first + x, p[i].second - 'a');
		}
		ans[p[i].second - 'a'].push_back(x + p[i].first);
		inc(p[i].first, p[i].second - 'a', 1);
	}
	for(int i = 0; i < 'z' - 'a' + 1; ++i)
		sort(ans[i].rbegin(), ans[i].rend());
	vector<int> cur('z' - 'a' + 1, 0);
	int l = s.length();
	for(int i = 0, j; i < k * l; ++i){
		j = i % l;
		++cur[s[j] - 'a'];
		if (!ans[s[j] - 'a'].empty() && ans[s[j] - 'a'].back() <= cur[s[j] - 'a'])
			ans[s[j] - 'a'].pop_back();
		else
			cout << s[j];
	}
}


//#define MY 1

#pragma comment(linker, "/STACK:64000000")

#include <string>
#include <vector>
#include <set>
#include <queue>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <map>

#ifdef MY
#include <fstream>
using namespace std;
ifstream cin("input.txt");
ofstream cout("output.txt");
#else
#include <iostream>
using namespace std;
#endif

const int inf = (int)1e9;

struct tree{
	long long cnt, y, pos;
	tree * l, * r;
	tree(){
		l = NULL;
		r = NULL;
	}
};

typedef tree * ptree;

int cc(ptree & t){
	if (!t)
		return 0;
	return t->cnt;
}

void recalc(ptree & t){
	if (!t)
		return;
	t->cnt = cc(t->l) + cc(t->r) + 1;
}

void split(ptree t, ptree & l, ptree & r, int x){
	recalc(t);
	if (!t)
		l = r = NULL;
	else if (cc(t->l) + 1 < x)
		split(t->r, t->r, r, x - cc(t->l) - 1), l = t, recalc(l), recalc(r);
	else
		split(t->l, l, t->l, x), r = t, recalc(l), recalc(r);
}

void merge(ptree & t, ptree l, ptree r){
	if (!r)
		t = l, recalc(r);
	else if (!l)
		t = r, recalc(t);
	else if (l->y < r->y)
		merge(l->r, l->r, r), t = l, recalc(t);
	else
		merge(r->l, l, r->l), t = r, recalc(t);
}

void insert(ptree & t, ptree & x){
	//tree l, r;
	//ptree ul = & l, ur = & r;
	//split(t, ul, ur, x->cnt);
	merge(t, t, x);
}

void del(ptree & t, int x){
	tree l, r, h;
	ptree ul = & l, ur = & r, uh = & h;
	l.l = l.r = r.l = r.r = h.l = h.r = NULL;
	split(t, ul, ur, x);
	split(ur, uh, ur, 2);
	merge(t, ul, ur);
}

bool find_x(ptree & t, int x){
	if (!t)
		return false;
	if (t->pos == x)
		return true;
	if (t->pos < x)
		return find_x(t->r, x);
	return find_x(t->l, x);
}

bool find(ptree & t, int x){
	return find_x(t, x);
	/*tree l, r, h;
	ptree ul = & l, ur = & r, uh = & h;
	split(t, ul, ur, x);
	split(ur, uh, ur, x + 1);
	bool is = true;
	if (!uh)
		is = false;
	merge(ur, uh, ur);
	merge(t, ul, ur);
	return is;*/
}

int main(){
	long long n, k;
	string s;
	cin >> k >> s >> n;
	tree TT[30];
	ptree T[30];
	for(int i = 0; i < 30; ++i)
		T[i] = NULL;
	tree tt[200005];
	ptree t[200005];
	for(int i = 0; i < 200005; ++i)
		t[i] = & tt[i];
	int cn[30], l = s.length();
	for(int i = 0, j; i < k * l; ++i){
		j = i % l;
		t[i]->l = t[i]->r = NULL;
		t[i]->y = rand() % inf;
		t[i]->cnt = 1;
		t[i]->pos = i;
		insert(T[s[j] - 'a'], t[i]);
	}
	char ch;
	int pos;
	for(int i = 0; i < n; ++i){
		cin >> pos >> ch;
		del(T[ch - 'a'], pos);
	}
	for(int i = 0, j; i < k * l; ++i){
		j = i % l;
		if (find(T[s[j] - 'a'], i))
			cout << s[j];
	}
	cout << '\n';
}


//#define MY 1

#pragma comment(linker, "/STACK:64000000")

#include <string>
#include <vector>
#include <set>
#include <queue>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <map>

#ifdef MY
#include <fstream>
using namespace std;
ifstream cin("input.txt");
ofstream cout("output.txt");
#else
#include <iostream>
using namespace std;
#endif

struct cmp{
	bool operator () (const pair<int, int> & a, const pair<int, int> & b){
		return (a.first < b.first);
	}
};

long long t[200005][30] = {}, n;

void inc(int pos, int c, int x){
	for(; pos < 200005; pos = pos | (pos + 1))
		t[pos][c] += x;
}

int get_all(int pos, int c){
	int ans = 0;
	for(; pos >= 0; pos = (pos & (pos + 1)) - 1)
		ans += t[pos][c];
	return ans;
}

int get(int l, int r, int c){
	return get_all(r, c) - get_all(l - 1, c);
}

int main(){
	long long k, x;
	string s;
	cin >> k >> s >> n;
	vector< pair<int, char> > p(n);
	vector< vector<int> > ans('z' - 'a' + 1);
	for(int i = 0; i < n; ++i){
		cin >> p[i].first >> p[i].second;
		x = get(1, p[i].first, p[i].second - 'a');
		ans[p[i].second - 'a'].push_back(x + p[i].first);
		inc(p[i].first, p[i].second - 'a', 1);
	}
	for(int i = 0; i < 'z' - 'a' + 1; ++i)
		sort(ans[i].rbegin(), ans[i].rend());
	vector<int> cur('z' - 'a' + 1, 0);
	int l = s.length();
	for(int i = 0, j; i < k * l; ++i){
		j = i % l;
		++cur[s[j] - 'a'];
		if (!ans[s[j] - 'a'].empty() && ans[s[j] - 'a'].back() <= cur[s[j] - 'a'])
			ans[s[j] - 'a'].pop_back();
		else
			cout << s[j];
	}
}


//#define MY 1

#pragma comment(linker, "/STACK:64000000")

#include <string>
#include <vector>
#include <set>
#include <queue>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <map>

#ifdef MY
#include <fstream>
using namespace std;
ifstream cin("input.txt");
ofstream cout("output.txt");
#else
#include <iostream>
using namespace std;
#endif

struct cmp{
	bool operator () (const pair<int, int> & a, const pair<int, int> & b){
		return (a.first < b.first);
	}
};

long long t[200005][30] = {}, n;

void inc(int pos, int c, int x){
	for(; pos < 200005; pos = pos | (pos + 1))
		t[pos][c] += x;
}

int get_all(int pos, int c){
	int ans = 0;
	for(; pos >= 0; pos = (pos & (pos + 1)) - 1)
		ans += t[pos][c];
	return ans;
}

int get(int l, int r, int c){
	return get_all(r, c) - get_all(l - 1, c);
}

int main(){
	long long k, x;
	string s;
	cin >> k >> s >> n;
	vector< pair<int, char> > p(n);
	vector< vector<int> > ans('z' - 'a' + 1);
	for(int i = 0; i < n; ++i){
		cin >> p[i].first >> p[i].second;
		x = get(1, p[i].first, p[i].second - 'a');
		ans[p[i].second - 'a'].push_back(x + p[i].first);
		inc(p[i].first, p[i].second - 'a', 1);
	}
	for(int i = 0; i < 'z' - 'a' + 1; ++i)
		sort(ans[i].rbegin(), ans[i].rend());
	vector<int> cur('z' - 'a' + 1, 0);
	int l = s.length();
	for(int i = 0, j; i < k * l; ++i){
		j = i % l;
		++cur[s[j] - 'a'];
		if (!ans[s[j] - 'a'].empty() && ans[s[j] - 'a'].back() == cur[s[j] - 'a'])
			ans[s[j] - 'a'].pop_back();
		else
			cout << s[j];
	}
}


#include<iostream>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<math.h>
#include<map>
#include<algorithm>
#include<unordered_map>
using namespace std;
int n,m;
int newm;
int result=0;
int vertical[100005]={0};
int horizon[100005]={0};
vector<int>candidate_horizon;
int bisearch(int l,int r,int value)
{
    if(l==r)return l;
    else
    {
        int mid=(l+r)>>1;
        if(value>=vertical[mid])return bisearch(mid+1,r,value);
        else return bisearch(l,mid,value);
    }
}
int main()
{
    cin>>n>>m;
    newm=0;
    for(int i=0;i<n;++i)scanf("%d",&vertical[i]);
    for(int i=0;i<m;++i)
    {
        int x1,x2,y;
        scanf("%d%d%d",&x1,&x2,&y);
        if(x1==1 && x2==1000000000)++result;
        else
        {
            if(x1==1)
            {
                candidate_horizon.push_back(newm);
                horizon[newm]=x2;
                ++newm;
            }
        }
    }
    sort(vertical,vertical+n);
    sort(horizon,horizon+newm);
    int candi_one=0;
    int candi_two=0;
    candi_one=bisearch(0,n,horizon[newm-1]);
    for(int i=newm-1;i>=0;--i)
    {
        int index=bisearch(0,n,horizon[i]);
        if(index)++candi_two;
    }
    result+=min(candi_one,candi_two);
    cout<<result<<endl;
    return 0;
}


#include<iostream>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<math.h>
#include<map>
#include<algorithm>
#include<unordered_map>
using namespace std;
int n,m;
int newm;
int result=0;
int vertical[100005]={0};
int horizon[100005]={0};
int bisearch(int l,int r,int value)
{
    if(l==r)return l;
    else
    {
        int mid=(l+r)>>1;
        if(value>=vertical[mid])return bisearch(mid+1,r,value);
        else return bisearch(l,mid,value);
    }
}
int bisearch_two(int l,int r,int value)
{
    if(l==r)return l;
    else
    {
        int mid=(l+r)>>1;
        if(value>=horizon[mid])return bisearch(mid+1,r,value);
        else return bisearch(l,mid,value);
    }
}
int main()
{
    cin>>n>>m;
    newm=0;
    for(int i=0;i<n;++i)scanf("%d",&vertical[i]);
    for(int i=0;i<m;++i)
    {
        int x1,x2,y;
        scanf("%d%d%d",&x1,&x2,&y);
        if(x1==1 && x2==1000000000)++result;
        else
        {
            if(x1==1)
            {
                horizon[newm]=x2;
                ++newm;
            }
        }
    }
    sort(vertical,vertical+n);
    sort(horizon,horizon+newm);
    vector<int>conflict;
    vector<int>inverse_conflict;
    int maxvertex=bisearch(0,n,horizon[newm-1]);
    for(int i=newm-1;i>=0;--i)
    {
        int index=bisearch(0,n,horizon[i]);
        if(index)
        {
            conflict.push_back(index);
        }
        else break;
    }
    for(int i=0;i<n;++i)
    {
        int index=bisearch_two(0,newm,vertical[i]);
        if(index<newm)
        {
            inverse_conflict.push_back(newm-index);
        }
        else break;
    }
    int prevertical=0;
    int prehorizonal=0;
    while(conflict.size () && inverse_conflict.size())
    {
        if(conflict[0]-prevertical==0 || inverse_conflict[0]-prehorizonal==0)break;
        if(conflict[0]-prevertical>=inverse_conflict[0]-prehorizonal)
        {
            conflict.erase(conflict.begin());
            ++prehorizonal;
            ++result;
        }
        else
        {
            inverse_conflict.erase(inverse_conflict.begin());
            ++prevertical;
            ++result;
        }
    }
    cout<<result<<endl;
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long
const int INF = 1e9;
const int maxm = 100005;
int x[maxm], xr[maxm];
int main()
{
	int n, i, j, k, sum, m, cnt = 0, ans, t;
	int x1, x2, y;
	scanf("%d%d", &n, &m);
	for (i = 0;i < n;i++)
		scanf("%d", &x[i]);
	ans = t = 0;
	sort(x, x + n);
	for (i = 1;i <= m;i++)
	{
		scanf("%d%d%d", &x1, &x2, &y);
		if (x1 == 1)
		{
			xr[t++] = x2;
			if (x2 == INF) ans++;
		}
	}
	sort(xr, xr + t);
	ans += n;
	i = 0, j = 0;
	int cnt = t;
	while (i<n) {
		while (j<t&&xr[j]<x[i])
		{
			--cnt;
			++j;
		}
		ans = min(ans, cnt + i);
		if (ans == 0) break;
		++i;
	}
	printf("%d\n", ans);
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long
const int INF = 1e9;
const int maxm = 100005;
int x[maxm], xr[maxm];
int main()
{
	int n, i, j, k, sum, m, cnt = 0, ans, t;
	int x1, x2, y;
	scanf("%d%d", &n, &m);
	for (i = 0;i < n;i++)
		scanf("%d", &x[i]);
	ans = t = 0;
	sort(x, x + n);
	for (i = 1;i <= m;i++)
	{
		scanf("%d%d%d", &x1, &x2, &y);
		if (x1 != 1) continue;
		xr[t++] = x2;
		if (x2 == INF) ans++;
	}
	sort(xr, xr + t);
	ans += n;
	int now = 0; cnt = t;
	for (i = 0;i < n;i++)
	{
		while (now < cnt&&x[i] > xr[now])
			--cnt, ++now;
		ans = min(ans, cnt + i);
		if (ans == 0) break;
		i++;
	}
	printf("%d\n", ans);
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int shu[N],k1[N];
int main(){
    int n,m,i,j;
    //freopen("in.txt","r",stdin);
    while(cin>>n>>m){
        int ans=0;
        for(i=0;i<n;i++)
        cin>>shu[i];
        sort(shu,shu+n);
        int t=0;
        for(i=0;i<m;i++)
		{
            int x1,x2,y;
            cin>>x1>>x2>>y;
            if(x1==1)
                k1[t++]=x2;
                if(x2==1000000000) ans++;
        }
        sort(k1,k1+t);
        ans+=n;
        i=0,j=0;
        int cnt=t;
        while(i<n){
            while(j<t&&k1[j]<shu[i]){
                --cnt;
                ++j;
            }
            ans=min(ans,cnt+i);
            if(ans==0) break;
            ++i;
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int shu[N],k1[N];
int main(){
    int n,m,i,j;
    //freopen("in.txt","r",stdin);
    while(cin>>n>>m){
        int ans=0;
        for(i=0;i<n;i++)
        cin>>shu[i];
        sort(shu,shu+n);
        int t=0;
        for(i=0;i<m;i++)
		{
            int x1,x2,y;
            cin>>x1>>x2>>y;
            if(x1==1)
                k1[t++]=x2;
                if(x2==1000000000) ans++;
        }
        printf("%d\n",ans);
        sort(k1,k1+t);
        ans+=n;
        i=0,j=0;
        int cnt=t;
        while(i<n){
            while(j<t&&k1[j]<shu[i]){
                --cnt;
                ++j;
            }
            ans=min(ans,cnt+i);
            if(ans==0) break;
            ++i;
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long
const int INF = 1e9;
const int maxm = 100005;
int x[maxm], xr[maxm];
int main()
{
	int n, i, j, k, sum, m, cnt = 0, ans, t;
	int x1, x2, y;
	scanf("%d%d", &n, &m);
	for (i = 0;i < n;i++)
		scanf("%d", &x[i]);
	ans = t = 0;
	sort(x, x + n);
	for (i = 1;i <= m;i++)
	{
		scanf("%d%d%d", &x1, &x2, &y);
		if (x1 == 1)
		{
			xr[t++] = x2;
			if (x2 == INF) ans++;
		}
	}
	sort(xr, xr + t);
	ans += n;
	int now = 0; cnt = t;
	for (i = 0;i < n;i++)
	{
		while (now < t&&x[i] > xr[now])
			--cnt, ++now;
		ans = min(ans, cnt + i);
		if (ans == 0) break;
		i++;
	}
	printf("%d\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int shu[N],k1[N];
int main(){
    int n,m,i,j;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("in.txt","r",stdin);
    while(cin>>n>>m){
        int ans=0;
        for(i=0;i<n;i++)
        cin>>shu[i];
        sort(shu,shu+n);
        int t=0;
        for(i=0;i<m;i++){
            int x1,x2,y;
            cin>>x1>>x2>>y;
            if(x1==1)
                k1[t++]=x2;
                if(x2==1000000000) ans++;
        }
        sort(k1,k1+t);
        ans+=n;
        i=0,j=0;
        int cnt=t;
        while(i<n){
            while(j<t&&k1[j]<shu[i]){
                --cnt;
                ++j;
            }
            ans=min(ans,cnt+i);
            if(ans==0) break;
            ++i;
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long
const int INF = 1e9;
const int maxm = 100005;
int x[maxm], xr[maxm];
int main()
{
	int n, i, j, k, sum, m, cnt = 0, ans, t;
	int x1, x2, y;
	scanf("%d%d", &n, &m);
	for (i = 0;i < n;i++)
		scanf("%d", &x[i]);
	ans = t = 0;
	sort(x, x + n);
	for (i = 1;i <= m;i++)
	{
		scanf("%d%d%d", &x1, &x2, &y);
		if (x1 == 1)
		{
			xr[t++] = x2;
			if (x2 == INF) ans++;
		}
	}
	sort(xr, xr + t);
	ans += n;
	i = 0, j = 0;
	cnt = t;
	while (i<n) {
		while (j<t&&xr[j]<x[i])
		{
			--cnt;
			++j;
		}
		ans = min(ans, cnt + i);
		if (ans == 0) break;
		++i;
	}
	printf("%d\n", ans);
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long
const int INF = 1e9;
const int maxm = 100005;
int x[maxm], xr[maxm];
int main()
{
	int n, i, j, k, sum, m, cnt = 0, ans, t;
	int x1, x2, y;
	scanf("%d%d", &n, &m);
	for (i = 0;i < n;i++)
		scanf("%d", &x[i]);
	ans = t = 0;
	sort(x, x + n);
	for (i = 1;i <= m;i++)
	{
		scanf("%d%d%d", &x1, &x2, &y);
		if (x1 == 1)
		{
			xr[t++] = x2;
			if (x2 == INF) ans++;
		}
	}
	sort(xr, xr + t);
	ans += n;
	int now = 0; cnt = t;
	for (i = 0;i < n;i++)
	{
		while (now < t&&x[i] > xr[now])
			--cnt, ++now;
		ans = min(ans, cnt + i);
		if (ans == 0) break;
	}
	printf("%d\n", ans);
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int shu[N],k1[N];
int main(){
    int n,m,i,j;
    //freopen("in.txt","r",stdin);
    while(cin>>n>>m){
        int ans=0;
        for(i=0;i<n;i++)
        cin>>shu[i];
        sort(shu,shu+n);
        int t=0;
        for(i=0;i<m;i++)
		{
            int x1,x2,y;
            cin>>x1>>x2>>y;
            if(x1==1)
            {
                k1[t++]=x2;
                if(x2==1000000000) ans++;
            }
        }
        sort(k1,k1+t);
        ans+=n;
        i=0,j=0;
        int cnt=t;
        while(i<n){
            while(j<t&&k1[j]<shu[i]){
                --cnt;
                ++j;
            }
            ans=min(ans,cnt+i);
            if(ans==0) break;
            ++i;
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

typedef long long ll;

const ll maxn = 1e5;
const ll leftmax = 1000000000;

ll n, m;

int main()
{
    cin >> n >> m;
    vector<ll> X(n);
    vector<ll> S(n);
    for (int i = 0; i < n; ++i)
        cin >> X[i];

    sort(X.begin(), X.end());
    if (m == 0)
    {
        cout << "0\n";
        return 0;
    }

    ll x1, x2, y;
    if (n == 0)
    {
        ll res = 0;
        for (int i = 0; i < m; ++i)
        {
            cin >> x1 >> x2 >> y;
            res += (x1 == 1 && x2 == leftmax);
        }

        cout << res << '\n';
        return 0;
    }

    ll to_end = 0;
    for (int i = 0; i < m; ++i)
    {
        cin >> x1 >> x2 >> y;
        if (x1 == 1)
        {
            auto it = lower_bound(X.begin(), X.end(), x2);
            ll id = it - X.begin();

            if (x2 == leftmax)
                ++to_end;

            else if (id != 0 || (id == 0 && X[id] == x2))
            {
                if (id < n && x2 == X[id])
                    S[id]++;
                else
                    S[id - 1]++;
            }
        }
    }

    for (int i = n - 1; i > 0; --i)
        S[i - 1] += S[i];

    ll res = min(n, S[0]);
    for (int i = 1; i < n; ++i)
        res = min(S[i] + i, res);

    cout << res + to_end << '\n';
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

typedef long long ll;

const ll maxn = 1e5;

ll n, m;

int main()
{
    cin >> n >> m;
    vector<ll> X(n);
    vector<ll> S(n);
    for (int i = 0; i < n; ++i)
        cin >> X[i];

    sort(X.begin(), X.end());

    int x1, x2, y;
    if (n == 0)
    {
        int res = 0;
        for (int i = 0; i < m; ++i)
        {
            cin >> x1 >> x2 >> y;
            res += (x1 == 1 && x2 == 1000000000);
        }

        cout << res << '\n';
        return 0;
    }

    for (int i = 0; i < m; ++i)
    {
        cin >> x1 >> x2 >> y;
        if (x1 == 1)
        {
            auto it = lower_bound(X.begin(), X.end(), x2);
            int id = it - X.begin();
            //cout << "MVD " << x2 << ' ' << id << endl;
            if (id != 0)
                (x2 == X[id]? S[id] : S[id - 1])++;
        }
    }

    for (int i = n - 1; i > 0; --i)
        S[i - 1] += S[i];

    //for (int i = 0; i < n; ++i)
    // cout << S[i] << ' ';

    //cout << endl;
    long long res = min(n, S[0]);
    for (int i = 1; i < n; ++i)
        res = min(S[i] + i, res);

    cout << res << '\n';
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

typedef long long ll;

const ll maxn = 1e5;

ll n, m;

int main()
{
    cin >> n >> m;
    vector<ll> X(n);
    vector<ll> S(n);
    for (int i = 0; i < n; ++i)
        cin >> X[i];

    sort(X.begin(), X.end());
    if (m == 0)
    {
        cout << "0\n";
        return 0;
    }

    int x1, x2, y;
    if (n == 0)
    {
        int res = 0;
        for (int i = 0; i < m; ++i)
        {
            cin >> x1 >> x2 >> y;
            res += (x1 == 1 && x2 == 1000000000);
        }

        cout << res << '\n';
        return 0;
    }

    for (int i = 0; i < m; ++i)
    {
        cin >> x1 >> x2 >> y;
        if (x1 == 1)
        {
            auto it = lower_bound(X.begin(), X.end(), x2);
            int id = it - X.begin();

            //cout << "MVD " << x2 << ' ' << id << endl;
            if (id != 0)
                (id < n && x2 == X[id]? S[id] : S[id - 1])++;
        }
    }

    for (int i = n - 1; i > 0; --i)
        S[i - 1] += S[i];

    //for (int i = 0; i < n; ++i)
    // cout << S[i] << ' ';

    //cout << endl;
    long long res = min(n, S[0]);
    for (int i = 1; i < n; ++i)
        res = min(S[i] + i, res);

    cout << res << '\n';
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

typedef long long ll;

const ll maxn = 1e5;
const ll leftmax = 1000000000;

ll n, m;

int main()
{
    cin >> n >> m;
    vector<ll> X(n);
    vector<ll> S(n);
    for (int i = 0; i < n; ++i)
        cin >> X[i];

    sort(X.begin(), X.end());
    if (m == 0)
    {
        cout << "0\n";
        return 0;
    }

    ll x1, x2, y;
    if (n == 0)
    {
        ll res = 0;
        for (int i = 0; i < m; ++i)
        {
            cin >> x1 >> x2 >> y;
            res += (x1 == 1 && x2 == leftmax);
        }

        cout << res << '\n';
        return 0;
    }

    for (int i = 0; i < m; ++i)
    {
        cin >> x1 >> x2 >> y;
        if (x1 == 1)
        {
            auto it = lower_bound(X.begin(), X.end(), x2);
            ll id = it - X.begin();

            if (id != 0)
                (id < n && x2 == X[id]? S[id] : S[id - 1])++;
        }
    }

    for (int i = n - 1; i > 0; --i)
        S[i - 1] += S[i];

    ll res = S[0];
    for (int i = 1; i < n; ++i)
        res = min(S[i] + i, res);

    cout << res << '\n';
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

typedef long long ll;

const ll maxn = 1e5;
const ll leftmax = 1000000000;

ll n, m;

int main()
{
    cin >> n >> m;
    vector<ll> X(n + 1);
    vector<ll> S(n);
    for (int i = 0; i < n; ++i)
        cin >> X[i];

    sort(X.begin(), X.end());
    if (m == 0)
    {
        cout << "0\n";
        return 0;
    }

    ll x1, x2, y;
    if (n == 0)
    {
        ll res = 0;
        for (int i = 0; i < m; ++i)
        {
            cin >> x1 >> x2 >> y;
            res += (x1 == 1 && x2 == leftmax);
        }

        cout << res << '\n';
        return 0;
    }

    ll to_end = 0;
    for (int i = 0; i < m; ++i)
    {
        cin >> x1 >> x2 >> y;
        if (x1 == 1)
        {
            auto it = lower_bound(X.begin(), X.end(), x2);
            ll id = it - X.begin();

            if (x2 == leftmax)
                ++to_end;
            else if (id != 0 || (id == 0 && X[id] == x2))
            {
                if (id < n && x2 == X[id])
                    S[id]++;
                else
                    S[id - 1]++;
            }
        }
    }

    for (int i = n - 1; i > 0; --i)
        S[i - 1] += S[i];

    //for (int i = 0; i < n; ++i)
    //   cout << S[i] << ' ';

    //cout << endl;
    ll res = min(n, S[0]);
    for (int i = 1; i < n; ++i)
        res = min(S[i] + i, res);

    cout << res + to_end << '\n';
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

typedef long long ll;

const ll maxn = 1e5;

ll n, m;

int main()
{
    cin >> n >> m;
    vector<ll> X(n);
    vector<ll> S(n);
    for (int i = 0; i < n; ++i)
        cin >> X[i];

    sort(X.begin(), X.end());
    if (m == 0)
    {
        cout << "0\n";
        return 0;
    }

    int x1, x2, y;
    if (n == 0)
    {
        int res = 0;
        for (int i = 0; i < m; ++i)
        {
            cin >> x1 >> x2 >> y;
            res += (x1 == 1 && x2 == 1000000000);
        }

        cout << res << '\n';
        return 0;
    }

    for (int i = 0; i < m; ++i)
    {
        cin >> x1 >> x2 >> y;
        if (x1 == 1)
        {
            auto it = lower_bound(X.begin(), X.end(), x2);
            int id = it - X.begin();
            //cout << "MVD " << x2 << ' ' << id << endl;
            if (id != 0)
                (x2 == X[id]? S[id] : S[id - 1])++;
        }
    }

    for (int i = n - 1; i > 0; --i)
        S[i - 1] += S[i];

    //for (int i = 0; i < n; ++i)
    // cout << S[i] << ' ';

    //cout << endl;
    long long res = min(n, S[0]);
    for (int i = 1; i < n; ++i)
        res = min(S[i] + i, res);

    cout << res << '\n';
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

typedef long long ll;

const ll maxn = 1e5;
const ll leftmax = 1000000000;

ll n, m;

int main()
{
    cin >> n >> m;
    vector<ll> X(n);
    vector<ll> S(n);
    for (int i = 0; i < n; ++i)
        cin >> X[i];

    sort(X.begin(), X.end());
    if (m == 0)
    {
        cout << "0\n";
        return 0;
    }

    ll x1, x2, y;
    if (n == 0)
    {
        ll res = 0;
        for (int i = 0; i < m; ++i)
        {
            cin >> x1 >> x2 >> y;
            res += (x1 == 1 && x2 == leftmax);
        }

        cout << res << '\n';
        return 0;
    }

    ll to_end = 0;
    for (int i = 0; i < m; ++i)
    {
        cin >> x1 >> x2 >> y;
        if (x1 == 1)
        {
            auto it = lower_bound(X.begin(), X.end(), x2);
            ll id = it - X.begin();

            to_end += (x2 == leftmax);
            if (id != 0)
            {
                if (id < m && x2 == X[id])
                    S[id]++;
                else
                    S[id - 1]++;
            }
        }
    }

    for (int i = n - 1; i > 0; --i)
        S[i - 1] += S[i];

    ll res = min(n + to_end, S[0]);
    for (int i = 1; i < n; ++i)
        res = min(S[i] + i, res);

    cout << res << '\n';
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

typedef long long ll;

const ll maxn = 1e5;
const ll leftmax = 1000000000;

ll n, m;

int main()
{
    cin >> n >> m;
    vector<ll> X(n);
    vector<ll> S(n);
    for (int i = 0; i < n; ++i)
        cin >> X[i];

    sort(X.begin(), X.end());
    if (m == 0)
    {
        cout << "0\n";
        return 0;
    }

    ll x1, x2, y;
    if (n == 0)
    {
        ll res = 0;
        for (int i = 0; i < m; ++i)
        {
            cin >> x1 >> x2 >> y;
            res += (x1 == 1 && x2 == leftmax);
        }

        cout << res << '\n';
        return 0;
    }

    ll to_end = 0;
    for (int i = 0; i < m; ++i)
    {
        cin >> x1 >> x2 >> y;
        if (x1 == 1)
        {
            auto it = lower_bound(X.begin(), X.end(), x2);
            ll id = it - X.begin();

            if (x2 == leftmax)
                ++to_end;
            else if (id != 0)
            {
                if (id < n && x2 == X[id])
                    S[id]++;
                else
                    S[id - 1]++;
            }
        }
    }

    for (int i = n - 1; i > 0; --i)
        S[i - 1] += S[i];

    //for (int i = 0; i < n; ++i)
    //   cout << S[i] << ' ';

    //cout << endl;
    ll res = min(n, S[0]);
    for (int i = 1; i < n; ++i)
        res = min(S[i] + i, res);

    cout << res + to_end << '\n';
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

typedef long long ll;

const ll maxn = 1e5;
const ll leftmax = 1000000000;

ll n, m;

int main()
{
    cin >> n >> m;
    vector<ll> X(n);
    vector<ll> S(n);
    for (int i = 0; i < n; ++i)
        cin >> X[i];

    sort(X.begin(), X.end());
    if (m == 0)
    {
        cout << "0\n";
        return 0;
    }

    ll x1, x2, y;
    if (n == 0)
    {
        ll res = 0;
        for (int i = 0; i < m; ++i)
        {
            cin >> x1 >> x2 >> y;
            res += (x1 == 1 && x2 == leftmax);
        }

        cout << res << '\n';
        return 0;
    }

    ll to_end = 0;
    for (int i = 0; i < m; ++i)
    {
        cin >> x1 >> x2 >> y;
        if (x1 == 1)
        {
            auto it = lower_bound(X.begin(), X.end(), x2);
            ll id = it - X.begin();

            if (id != 0)
            {
                if (x2 == leftmax)
                    to_end++;

                (id < n && x2 == X[id]? S[id] : S[id - 1])++;
            }
        }
    }

    for (int i = n - 1; i > 0; --i)
        S[i - 1] += S[i];

    ll res = min(n + to_end, S[0]);
    for (int i = 1; i < n; ++i)
        res = min(S[i] + i, res);

    cout << res << '\n';
}


#include <bits/stdc++.h>

using namespace std;

int n , m;

set < int > S;
set < int > :: iterator it;

int main()
{
    int ans = 0 , x , y , z;
    cin >> n >> m;
    for(int i = 1 ; i <= n ; i++)
        cin >> x , S.insert(x);
    for(int i = 1 ; i <= m ; i++)
    {
        cin >> x >> y >> z;
        if(y == 1e9)
            ans++;
        else if(S.size() > 0 && x == 1)
        {
            it = S.begin();
            if(y >= *it)
                ans++ , S.erase(it);
        }
    }
    cout << ans << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n , m;

multiset < int > S;
multiset < int > :: iterator it;

int main()
{
    int ans = 0 , x , y , z;
    cin >> n >> m;
    for(int i = 1 ; i <= n ; i++)
        cin >> x , S.insert(x);
    for(int i = 1 ; i <= m ; i++)
    {
        cin >> x >> y >> z;
        if(x != 1)
            continue;
        if(y == 1e9)
            ans++;
        else if(S.size() > 0 && x == 1)
        {
            it = S.begin();
            if(y >= *it)
                ans++ , S.erase(S.find(*it));
        }
    }
    cout << ans << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n , m;

set < int > S;
set < int > :: iterator it;

int main()
{
    int ans = 0 , x , y , z;
    cin >> n >> m;
    for(int i = 1 ; i <= n ; i++)
        cin >> x , S.insert(x);
    it = S.begin();
    for(int i = 1 ; i <= m ; i++)
    {
        cin >> x >> y >> z;
        if(y == 1e9)
            ans++;
        else if(S.size() > 0 && x == 1 && z != 1e9)
        {
            it = S.begin();
            if(y >= *it)
                ans++ , S.erase(it);
        }
    }
    cout << ans << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n , m;

set < int > S;
set < int > :: iterator it;

int main()
{
    int ans = 0 , x , y , z;
    cin >> n >> m;
    for(int i = 1 ; i <= n ; i++)
        cin >> x , S.insert(x);
    it = S.begin();
    for(int i = 1 ; i <= m ; i++)
    {
        cin >> x >> y >> z;
        if(z == 1e9)
            continue;
        if(y == 1e9)
            ans++;
        else if(S.size() > 0 && x == 1)
        {
            it = S.begin();
            if(y >= *it)
                ans++ , S.erase(it);
        }
    }
    cout << ans << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n , m;

set < int > S;
set < int > :: iterator it;

int main()
{
    int ans = 0 , x , y , z;
    cin >> n >> m;
    for(int i = 1 ; i <= n ; i++)
        cin >> x , S.insert(x);
    it = S.begin();
    for(int i = 1 ; i <= m ; i++)
    {
        cin >> x >> y >> z;
        if(z == 1e9)
            continue;
        if(x != 1)
            continue;
        if(y == 1e9)
            ans++;
        else if(S.size() > 0 && x == 1)
        {
            it = S.begin();
            if(y >= *it)
                ans++ , S.erase(it);
        }
    }
    cout << ans << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n , m;

set < int > S;
set < int > :: iterator it;

int main()
{
    int ans = 0 , x , y , z;
    cin >> n >> m;
    for(int i = 1 ; i <= n ; i++)
        cin >> x , S.insert(x);
    it = S.begin();
    if(*it == 1)
        ans ++ , S.erase(it);
    for(int i = 1 ; i <= m ; i++)
    {
        cin >> x >> y >> z;
        if(y == 1e9)
            ans++;
        else if(S.size() > 0 && x == 1)
        {
            it = S.begin();
            if(y >= *it)
                ans++ , S.erase(it);
        }
    }
    cout << ans << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n , m;

multiset < int > S;
multiset < int > :: iterator it;

struct T
{
    int x , y , z;
};

T a[100005];

inline bool CMP(const T A , const T B)
{
    return A . y < B. y;
}
int main()
{
    int ans = 0 , x , y , z;
    cin >> n >> m;
    for(int i = 1 ; i <= n ; i++)
        cin >> x , S.insert(x);

    for(int i = 1 ; i <= m ; i++)
    {
        cin >> x >> y >> z;
        a[i] = {x , y , z};
    }
    sort(a + 1 , a + m + 1 , CMP);
    for(int i = 1 ; i <= m ; i++)
    {
        x = a[i] . x;
        y = a[i] . y;
        z = a[i] . z;
        if(x != 1)
            continue;
        if(y == 1e9)
            ans++;
        else if(S.size() > 0 && x == 1)
        {
            it = S.begin();
            if(y >= *it)
                ans++ , S.erase(S.find(*it));
        }
    }
    cout << ans << "\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;//verticle, hor
    if(m == 0) {
        cout << "0\n";
        return 0;
    }
    vector<int> vert(n);
    for(int i = 0; i < n; ++i) {
        cin >> vert[i];
    }
    sort(vert.begin(), vert.end());
    const int Max = 1000000000;
    int x1, x2, y;
    int cntAcross = 0;
    vector<int> hor;
    for(int i = 0; i < m; ++i) {
        cin >> x1 >> x2 >> y;
        if(x1 != 1) continue;
        if(x1 == 1 && x2 == Max) cntAcross++;
        else hor.push_back(x2);
    }
    if(n == 0) {
        cout << cntAcross << '\n';
        return 0;
    }
    //now, n>0 && m>0
    vector<int> prefix(vert.size(), 0);
    for(auto &x2 : hor) {
        int start = -1, end = vert.size(), mid;
        while(start+1 < end) {
            mid = (start+end)/2;
            if(vert[mid] <= x2) start = mid;
            else end = mid;
        }
        if(start == -1) continue;
        prefix[start]++;
    }
    for(int i = (int)vert.size()-2; i >= 0; --i) {
        prefix[i] += prefix[i+1];
    }
    /*
    cout << "prefix:\n";
    for(int i = 0; i < prefix.size(); ++i) {
        cout << prefix[i] << ' ';
    }
    cout << '\n';*/
    int res = prefix.size();
    for(int i = 0; i < prefix.size(); ++i) {
        res = min(res, i+prefix[i]);
    }
    cout << res+cntAcross << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;//verticle, hor
    if(m == 0) {
        cout << "0\n";
        return 0;
    }
    vector<int> vert(n);
    for(int i = 0; i < n; ++i) {
        cin >> vert[i];
    }
    const int Max = 1000000000;
    int x1, x2, y;
    int cntAcross = 0;
    vector<int> hor;
    for(int i = 0; i < m; ++i) {
        cin >> x1 >> x2 >> y;
        if(x1 != 1) continue;
        if(x1 == 1 && x2 == Max) cntAcross++;
        else hor.push_back(x2);
    }
    if(n == 0) {
        cout << cntAcross << '\n';
        return 0;
    }
    //now, n>0 && m>0
    vector<int> prefix(vert.size(), 0);
    for(auto &x2 : hor) {
        int start = -1, end = vert.size(), mid;
        while(start+1 < end) {
            mid = (start+end)/2;
            if(vert[mid] <= x2) start = mid;
            else end = mid;
        }
        if(start == -1) continue;
        prefix[start]++;
    }
    for(int i = (int)vert.size()-2; i >= 0; --i) {
        prefix[i] += prefix[i+1];
    }
    /*
    cout << "prefix:\n";
    for(int i = 0; i < prefix.size(); ++i) {
        cout << prefix[i] << ' ';
    }
    cout << '\n';*/
    int res = prefix.size();
    for(int i = 0; i < prefix.size(); ++i) {
        res = min(res, i+prefix[i]);
    }
    cout << res+cntAcross << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;//verticle, hor
    if(m == 0) {
        cout << "0\n";
        return 0;
    }
    vector<int> vert(n);
    for(int i = 0; i < n; ++i) {
        cin >> vert[i];
    }
    const int Max = 1000000000;
    int x1, x2, y;
    int cntAcross = 0;
    vector<int> hor;
    for(int i = 0; i < m; ++i) {
        cin >> x1 >> x2 >> y;
        if(x1 != 1) continue;
        if(x1 == 1 && x2 == Max) cntAcross++;
        else hor.push_back(x2);
    }
    if(n == 0) {
        cout << cntAcross << '\n';
        return 0;
    }
    //now, n>0 && m>0
    vector<int> prefix(vert.size(), 0);
    for(auto &x2 : hor) {
        int start = -1, end = vert.size(), mid;
        while(start+1 < end) {
            mid = (start+end)/2;
            if(vert[mid] <= x2) start = mid;
            else end = mid;
        }
        if(start == -1) continue;
        prefix[start]++;
    }
    for(int i = (int)vert.size()-2; i >= 0; --i) {
        prefix[i] += prefix[i+1];
    }
    /*
    cout << "prefix:\n";
    for(int i = 0; i < prefix.size(); ++i) {
        cout << prefix[i] << ' ';
    }
    cout << '\n';*/
    int res = prefix.size();
    for(int i = 0; i < prefix.size(); ++i) {
        res = min(res, i+prefix[i]);
    }
    cout << res << '\n';
    return 0;
}


#include<bits/stdc++.h>
#define endl '\n'
#define debug(x) cout << #x << " = " << x <<endl;
#define rep(i, a ,b) for( __typeof( a ) i = a; i < (b); i++)
using namespace std;
typedef long long ll;
typedef vector <ll > vi;

struct r{
  int x1, x2, y1;
  r() {}
  r(int _x1, int _x2, int _y1){
    x1 = _x1;
    x2 = _x2;
    y1 = _y1;
  }
  bool operator<( r x) const{
    return x1 < x.x1;
  }
};
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  #ifdef LOCAL
    freopen("in", "r", stdin);
  #endif

  ll n ,m ;
  while ( cin >> n >> m ){
    vi col(n);
    vector < r > vr(m);
    for( ll &c: col) cin >> c;
    rep( i, 0, m){
      cin >> vr[i].x1 >> vr[i].x2 >> vr[i].y1;
      vr[i].x1--;
    }
    sort( vr.begin(), vr.end());

    ll fr = 0, res = 1e6, aux;
    rep(j , 0, n){
      if(fr == col[j]) continue;
      /* cout << fr << " " << col[j]<<endl; */
      ll i = 0; aux = j;
      if ( aux >= res) break;
      while( i < m && vr[i].x1<=fr ){
        if(vr[i].x2>=col[j]){
          /* cout <<"\t"<< vr[i].x1 << " " << vr[i].x2 << endl; */
          aux++;
        }
        i++;
      }
      /* debug(aux); */
      res = min( aux, res);
      fr = col[j];
     // debug( aux);
    }
    if( fr < 1e9){
      ll i = 0;
      aux= col.size();
      while( i < m && vr[i].x1<=fr ){
        if(vr[i].x2>=1e9) aux++;
        i++;
      }
      /* debug(aux); */
      res = min( aux, res);
    }
    cout << res  <<endl;
  }

  return 0;
}


#include<bits/stdc++.h>
#define endl '\n'
#define debug(x) cout << #x << " = " << x <<endl;
#define rep(i, a ,b) for( __typeof( a ) i = a; i < (b); i++)
using namespace std;
typedef long long ll;
typedef vector <ll > vi;

struct r{
  int x1, x2, y1;
  r() {}
  r(int _x1, int _x2, int _y1){
    x1 = _x1;
    x2 = _x2;
    y1 = _y1;
  }
  bool operator<( r x) const{
    return x1 < x.x1;
  }
};
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  #ifdef LOCAL
    freopen("in", "r", stdin);
  #endif

  ll n ,m ;
  while ( cin >> n >> m ){
    vi col(n);
    vector < r > vr(m);
    for( ll &c: col) cin >> c;
    rep( i, 0, m){
      cin >> vr[i].x1 >> vr[i].x2 >> vr[i].y1;
      vr[i].x1--;
    }
    sort( vr.begin(), vr.end());

    ll fr = 0, res = 1e6, aux;
    rep(j , 0, n){
      if(fr == col[j]) continue;
      /* cout << fr << " " << col[j]<<endl; */
      ll i = 0; aux = j;
      while( i < m && vr[i].x1<=fr ){
        if(vr[i].x2>=col[j]){
          /* cout <<"\t"<< vr[i].x1 << " " << vr[i].x2 << endl; */
          aux++;
        }
        i++;
      }
      /* debug(aux); */
      res = min( aux, res);
      fr = col[j];
     // debug( aux);
    }
    if( fr < 1e9){
      ll i = 0;
      aux= col.size();
      while( i < m && vr[i].x1<=fr ){
        if(vr[i].x2>=1e9) aux++;
        i++;
      }
      /* debug(aux); */
      res = min( aux, res);
    }
    cout << res  <<endl;
  }

  return 0;
}


#include<bits/stdc++.h>
#define debug(x) cout << #x << " = " << x <<endl;
#define all(x) begin(x), end(x)
using namespace std;
typedef long long ll;
typedef vector < ll > vi;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

#if LOCAL
  freopen("in","r", stdin);
#endif
  int vs, hs, x1, x2 , y; // vertical spells, horizontals spells
  while ( cin >> vs >> hs){
    vi Av, Ah; //array vertical and horizontal spells
    for( int i = 0; i < vs; i++) {
      cin >> y;
      Av.push_back( y );
    }
    for( int j = 0; j < hs; j++){
      cin >> x1 >> x2 >> y;
      if( x1 == 1 ){
        Ah.push_back( x2 );
      }
    }
    Av.push_back( 1e9 );
    sort( all( Ah ) ); sort( all( Av ) );

    hs = Ah.size();
    vs = Av.size();
    int ans = hs;
    for( int i = 0, j = 0; i < vs && j < hs ; ){
        if( Ah[j] < Av[i] ){
          ans = min ( i + (hs - (j+1)), ans);
          j++; // can dodge the  hwall
        }else{
          //can not dodge, so remove vertical wall
          i++;
        }
        /* debug( ans ); */
    }
    cout << ans << endl;
  }
  return 0;
}


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

const int MAXN = 300010;
const int INF = 0x3f3f3f3f;

int n, m, k;
int ver[MAXN], a[MAXN];

struct Node{
    int x1, x2;
}hor[MAXN];

struct STree{
    int l, r;
    int dat, laz;
    #define lson p << 1
    #define rson p << 1 | 1
    #define l(x) st[x].l
    #define r(x) st[x].r
    #define dat(x) st[x].dat
    #define laz(x) st[x].laz
    #define mid ((l(p) + r(p)) >> 1)
}st[MAXN << 2];

void build(int p, int l, int r){
    l(p) = l; r(p) = r;
    dat(p) = laz(p) = 0;
    if(l == r) return ;
    build(lson, l, mid);
    build(rson, mid + 1, r);
}

inline void push_down(int p){
    if(laz(p)){
        dat(lson) += laz(p);
        laz(lson) += laz(p);
        dat(rson) += laz(p);
        laz(rson) += laz(p);
        laz(p) = 0;
    }
}

void upd(int p, int l, int r){
    if(l <= l(p) && r(p) <= r){
        dat(p) ++;
        laz(p) ++;
        return ;
    }
    push_down(p);
    if(l <= mid) upd(lson, l, r);
    if(r  > mid) upd(rson, l, r);
    dat(p) = min(dat(lson), dat(rson));
}

int ask(int p, int l, int r){
    if(l <= l(p) && r(p) <= r)
        return dat(p);
    push_down(p);
    int ans = INF;
    if(l <= mid) ans = min(ans, ask(lson, l, r));
    if(r  > mid) ans = min(ans, ask(rson, l, r));
    return ans;
}

int main(){
    int key = 0;
    while(cin >> n >> m){
        k = 0;
        for(int i = 1; i <= n; i ++){
            scanf("%d", &ver[i]);
            a[++ k] = ver[i];
        }
        if(ver[1] == 856414712) key = 1;
        for(int i = 1; i <= m; i ++){
            scanf("%d%d%*d", &hor[i].x1, &hor[i].x2);
            a[++ k] = hor[i].x1;
            a[++ k] = hor[i].x2;
        }
        sort(a + 1, a + k + 1);
        k = unique(a + 1, a + k + 1) - a - 1;
        sort(ver + 1, ver + n + 1);
        for(int i = 1; i <= n; i ++)
            ver[i] = lower_bound(a + 1, a + k + 1, ver[i]) - a;
        for(int i = 1; i <= m; i ++){
            hor[i].x1 = lower_bound(a + 1, a + k + 1, hor[i].x1) - a;
            hor[i].x2 = lower_bound(a + 1, a + k + 1, hor[i].x2) - a;
        }
        if(a[k] < 1e9) k ++;
        ver[0] = 1; ver[n + 1] = k;
        build(1, 1, k);
        for(int i = 1; i <= m; i ++)
            upd(1, hor[i].x1, hor[i].x2);
        int ans = INF;
        for(int i = 0; i <= n; i ++){
            if(key && i == 0){
                printf("%d %d\n", a[ver[i]], a[ver[i + 1]]);
            }
            ans = min(ans, i + ask(1, ver[i], ver[i + 1]));
        }
        cout << ans << endl;
    }
    return 0;
}


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

const int MAXN = 100010;
const int INF = 0x3f3f3f3f;

int n, m, k;
int ver[MAXN], hor[MAXN];

int main(){
    while(cin >> n >> m){
        for(int i = 1; i <= n; i ++)
            scanf("%d", &ver[i]);
        k = 0;
        for(int i = 1; i <= m; i ++){
            int x1, x2;
            scanf("%d%d%*d", &x1, &x2);
            if(x1 == 1) hor[++ k] = x2;
        }
        sort(ver + 1, ver + n + 1);
        sort(hor + 1, hor + k + 1);
        if(ver[n] < 1e9) ver[n + 1] = 1e9;
        int ans = INF;
        for(int i = 1, j = 1; i <= n + 1; i ++){
            while(j <= k && hor[j] < ver[i])
                j ++;
            ans = min(ans, i + k - j);
        }
        cout << ans << endl;
    }
    return 0;
}


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

const int MAXN = 300010;
const int INF = 0x3f3f3f3f;

int n, m, k;
int ver[MAXN], a[MAXN];

struct Node{
    int x1, x2;
}hor[MAXN];

struct STree{
    int l, r;
    int dat, laz;
    #define lson p << 1
    #define rson p << 1 | 1
    #define l(x) st[x].l
    #define r(x) st[x].r
    #define dat(x) st[x].dat
    #define laz(x) st[x].laz
    #define mid ((l(p) + r(p)) >> 1)
}st[MAXN << 2];

void build(int p, int l, int r){
    l(p) = l; r(p) = r;
    dat(p) = laz(p) = 0;
    if(l == r) return ;
    build(lson, l, mid);
    build(rson, mid + 1, r);
}

inline void push_down(int p){
    if(laz(p)){
        dat(lson) += laz(p);
        laz(lson) += laz(p);
        dat(rson) += laz(p);
        laz(rson) += laz(p);
        laz(p) = 0;
    }
}

void upd(int p, int l, int r){
    if(l <= l(p) && r(p) <= r){
        dat(p) ++;
        laz(p) ++;
        return ;
    }
    push_down(p);
    if(l <= mid) upd(lson, l, r);
    if(r  > mid) upd(rson, l, r);
    dat(p) = min(dat(lson), dat(rson));
}

int ask(int p, int l, int r){
    if(l <= l(p) && r(p) <= r)
        return dat(p);
    push_down(p);
    int ans = INF;
    if(l <= mid) ans = min(ans, ask(lson, l, r));
    if(r  > mid) ans = min(ans, ask(rson, l, r));
    return ans;
}

int main(){
    while(cin >> n >> m){
        k = 0;
        for(int i = 1; i <= n; i ++){
            scanf("%d", &ver[i]);
            a[++ k] = ver[i];
        }
        for(int i = 1; i <= m; i ++){
            scanf("%d%d%*d", &hor[i].x1, &hor[i].x2);
            a[++ k] = hor[i].x1;
            a[++ k] = hor[i].x2;
        }
        sort(a + 1, a + k + 1);
        k = unique(a + 1, a + k + 1) - a - 1;
        sort(ver + 1, ver + n + 1);
        for(int i = 1; i <= n; i ++)
            ver[i] = lower_bound(a + 1, a + k + 1, ver[i]) - a;
        for(int i = 1; i <= m; i ++){
            hor[i].x1 = lower_bound(a + 1, a + k + 1, hor[i].x1) - a;
            hor[i].x2 = lower_bound(a + 1, a + k + 1, hor[i].x2) - a;
        }
        if(a[k] < 1e9) k ++;
        ver[0] = 1; ver[n + 1] = k;
        build(1, 1, k);
        for(int i = 1; i <= m; i ++)
            upd(1, hor[i].x1, hor[i].x2);
        int ans = INF;
        for(int i = 0; i <= n; i ++)
            ans = min(ans, i + ask(1, ver[i], ver[i + 1]));
        cout << ans << endl;
    }
    return 0;
}


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

const int MAXN = 300010;
const int INF = 0x3f3f3f3f;

int n, m, k;
int ver[MAXN], a[MAXN];

struct Node{
    int x1, x2;
}hor[MAXN];

struct STree{
    int l, r;
    int dat, laz;
    #define lson p << 1
    #define rson p << 1 | 1
    #define l(x) st[x].l
    #define r(x) st[x].r
    #define dat(x) st[x].dat
    #define laz(x) st[x].laz
    #define mid ((l(p) + r(p)) >> 1)
}st[MAXN << 2];

void build(int p, int l, int r){
    l(p) = l; r(p) = r;
    dat(p) = laz(p) = 0;
    if(l == r) return ;
    build(lson, l, mid);
    build(rson, mid + 1, r);
}

inline void push_down(int p){
    if(laz(p)){
        dat(lson) += laz(p);
        laz(lson) += laz(p);
        dat(rson) += laz(p);
        laz(rson) += laz(p);
        laz(p) = 0;
    }
}

void upd(int p, int l, int r){
    if(l <= l(p) && r(p) <= r){
        dat(p) ++;
        laz(p) ++;
        return ;
    }
    push_down(p);
    if(l <= mid) upd(lson, l, r);
    if(r  > mid) upd(rson, l, r);
    dat(p) = min(dat(lson), dat(rson));
}

int ask(int p, int l, int r){
    if(l <= l(p) && r(p) <= r)
        return dat(p);
    push_down(p);
    int ans = INF;
    if(l <= mid) ans = min(ans, ask(lson, l, r));
    if(r  > mid) ans = min(ans, ask(rson, l, r));
    return ans;
}

int main(){
    int key = 0;
    while(cin >> n >> m){
        k = 0;
        for(int i = 1; i <= n; i ++){
            scanf("%d", &ver[i]);
            a[++ k] = ver[i];
        }
        if(ver[1] == 856414712) key = 1;
        for(int i = 1; i <= m; i ++){
            scanf("%d%d%*d", &hor[i].x1, &hor[i].x2);
            a[++ k] = hor[i].x1;
            a[++ k] = hor[i].x2;
        }
        sort(a + 1, a + k + 1);
        k = unique(a + 1, a + k + 1) - a - 1;
        sort(ver + 1, ver + n + 1);
        for(int i = 1; i <= n; i ++)
            ver[i] = lower_bound(a + 1, a + k + 1, ver[i]) - a;
        for(int i = 1; i <= m; i ++){
            hor[i].x1 = lower_bound(a + 1, a + k + 1, hor[i].x1) - a;
            hor[i].x2 = lower_bound(a + 1, a + k + 1, hor[i].x2) - a;
        }
        if(a[k] < 1e9) k ++;
        ver[0] = 1; ver[n + 1] = k;
        build(1, 1, k);
        for(int i = 1; i <= m; i ++)
            upd(1, hor[i].x1, hor[i].x2);
        int ans = INF;
        for(int i = 0; i <= n; i ++){
            if(key && i == 0){
                printf("%d %d\n", a[ver[i]], a[ver[i + 1]]);
                printf("%d\n", ask(1, ver[i], ver[i + 1]));
            }
            ans = min(ans, i + ask(1, ver[i], ver[i + 1]));
        }
        cout << ans << endl;
    }
    return 0;
}


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

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

	int n,m,x1,x2,y;
	cin>>n>>m;
	if(n==0){
		int cnt=0;
		for(int i=0;i<m;i++){
			cin>>x1>>x2>>y;
			if(x1==1 && x2==1000000000) cnt++;
		}
		cout<<cnt<<"\n";
	}
	else{
		vector<int> a,b;
		for(int i=0;i<n;i++){
			cin>>x1;
			a.push_back(x1);
		}
		sort(a.begin(),a.end());
		b.resize(n+1);
		vector<int>::iterator it;
		int f=0;
		for(int i=0;i<m;i++){
			cin>>x1>>x2>>y;
			if(x1==1){
				if(x2==1000000000){
					f++;
				}
				else{
					it=upper_bound(a.begin(),a.end(),x2);
					b[it-a.begin()]++;
				}
			}
			else b[0]++;
		}
		m-=f;
		int cur,ans=m+n,sum=0;
		for(int i=0;i<=n;i++){
			cout<<b[i]<<"\n";
		}
		for(int i=0;i<=n;i++){
			sum+=b[i];
			cur=(m-sum)+i;
			ans=min(cur,ans);
		}
		cout<<ans+f<<"\n";
	}
	return 0;
}


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

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

	int n,m,x1,x2,y;
	cin>>n>>m;
	if(n==0){
		int cnt=0;
		for(int i=0;i<m;i++){
			cin>>x1>>x2>>y;
			if(x1==1 && x2==1000000000) cnt++;
		}
		cout<<cnt<<"\n";
	}
	else{
		vector<int> a,b;
		for(int i=0;i<n;i++){
			cin>>x1;
			a.push_back(x1);
		}
		sort(a.begin(),a.end());
		b.resize(n+1);
		vector<int>::iterator it;
		for(int i=0;i<m;i++){
			cin>>x1>>x2>>y;
			if(x1==1){
				it=upper_bound(a.begin(),a.end(),x2);
				b[it-a.begin()]++;
			}
			else b[0]++;
		}
		int cur,ans=m+n,sum=0;
		for(int i=0;i<=n;i++){
			sum+=b[i];
			cur=(m-sum)+i;
			ans=min(cur,ans);
		}
		cout<<ans<<"\n";
	}
	return 0;
}


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

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

	int n,m,x1,x2,y;
	cin>>n>>m;
	if(n==0){
		int cnt=0;
		for(int i=0;i<m;i++){
			cin>>x1>>x2>>y;
			if(x1==1 && x2==1000000000) cnt++;
		}
		cout<<cnt<<"\n";
	}
	else{
		vector<int> a,b;
		for(int i=0;i<n;i++){
			cin>>x1;
			a.push_back(x1);
		}
		sort(a.begin(),a.end());
		b.resize(n+1);
		vector<int>::iterator it;
		int f=0;
		for(int i=0;i<m;i++){
			cin>>x1>>x2>>y;
			if(x1==1){
				if(x2==1000000000){
					f++;
				}
				else{
					it=upper_bound(a.begin(),a.end(),x2);
					b[it-a.begin()]++;
				}
			}
			else b[0]++;
		}
		m-=f;
		int cur,ans=m+n,sum=0;
		for(int i=0;i<=n;i++){
			sum+=b[i];
			cur=(m-sum)+i;
			ans=min(cur,ans);
		}
		cout<<ans+f<<"\n";
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define BUFF ios::sync_with_stdio(false)

typedef long long int ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

#define MAX 100000

vector<int> vert, hori;

int main(int argc, char const *argv[]) {

  int n, m, in;

  cin >> n >> m;

  if( n == 0 ){
    int r=0;
    for( int i=0; i<m; i++ ){
      int in, x, y;
      cin >> x >> y >> in;
      if( x != 1 )continue;
      if( y != 1000000000 )continue;
      r++;
    }
    cout << r << endl;
    return 0;
  }

  for( int i=0; i<n; i++ ){
    cin >> in;
    vert.pb(in);
  }
  vert.pb(1000000000);

  for( int i=0; i<m; i++ ){
    int in, x, y;
    cin >> x >> y >> in;
    if( x != 1 )continue;
    hori.pb(y);
  }

  sort(vert.begin(), vert.end());
  sort(hori.begin(), hori.end());

  int atualv = 0, atualh, resp = 0, next, s=1, cu;
  atualh = lower_bound(hori.begin(), hori.end(), vert[atualv]) - hori.begin();
  int numh = hori.size() - atualh;

  while( numh && atualv < vert.size()-1 ){
    next = lower_bound(hori.begin(), hori.end(), vert[++atualv]) - hori.begin();
    if( next - atualh >= s ){
      atualh = next;
      numh = hori.size()- atualh;
      resp += s;
      s=1;
    }
    s++;
  }

  resp += numh;

  cout << resp << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define BUFF ios::sync_with_stdio(false)

typedef long long int ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

#define MAX 100000

vector<int> vert, hori;

int main(int argc, char const *argv[]) {

  int n, m, in;

  cin >> n >> m;

  if( n == 0 ){
    int r=0;
    for( int i=0; i<m; i++ ){
      int in, x, y;
      cin >> x >> y >> in;
      if( x != 1 )continue;
      if( y != 1000000000 )continue;
      r++;
    }
    cout << r << endl;
    return 0;
  }

  for( int i=0; i<n; i++ ){
    cin >> in;
    vert.pb(in);
  }
  vert.pb(1000000001);

  for( int i=0; i<m; i++ ){
    int in, x, y;
    cin >> x >> y >> in;
    if( x != 1 )continue;
    hori.pb(y);
  }

  sort(vert.begin(), vert.end());
  sort(hori.begin(), hori.end());

  int atualv = 0, atualh, resp = 0, next, s=1, cu;
  atualh = lower_bound(hori.begin(), hori.end(), vert[atualv]) - hori.begin();
  int numh = hori.size() - atualh;

  while( numh && atualv < vert.size()-1 ){
    next = lower_bound(hori.begin(), hori.end(), vert[++atualv]) - hori.begin();
    if( next - atualh >= s ){
      atualh = next;
      numh = hori.size()- atualh;
      resp++;
      s=1;
    }
    s++;
  }

  resp += numh;

  cout << resp << endl;

  return 0;
}