#include <iostream>
#define MAX_SIZE 100000
#define MAX_SIZE2 1000000
using namespace std;
int sorted[MAX_SIZE];
int n;
long long q,query;
struct heap{
    int size,sizeH;
    heap(){
        size = 0 ;
        sizeH = 0;
    }

    int pq[MAX_SIZE];
    int parent (int leaf) {return (leaf-1)/2;}
    int left (int s) {return s*2 +1;}
    int right (int s) {return s*2 +2;}
    void swap(int *a,int *b){
        int temp = *a;
        *a = *b;
        *b = temp;
    }
    void add (int e){
       int index = size;
       pq[size++] = e;
       while(index>0){
           if (pq[parent(index)]< pq[index])
                swap(&pq[parent(index)],&pq[index]);
           index = parent(index);
       }
    }
    int remove(){
        int index = size--;
        int maior = pq[0];
        pq[0] = pq[index];
        heapfy(0);
        return maior;
    }
    void heapfy(int index){
        while(index<size){
            int s = index;
            int l = left(index);
            int r = right(index);
            if(pq[index]< pq[l]){
                index = l;
            }
            if(pq[index]<pq[r]){
                index = r;
            }
            if (index == s)
                break;
            swap(&pq[index],&pq[parent(index)]);
        }
    }
    bool isEmpty(){
        return size ==0;
    }
    void heapSort(){
        while(!isEmpty()){
            sorted[size] =  remove();
            sizeH++;
        }
    }
    void deBug(){
        for(int i = 0 ; i < sizeH ; i++){
            cout << sorted[i] << " ";
        }
        cout <<endl;
    }
    int get(int e){
        return sorted[e];
    }
};
struct heap h;
int binary_search(int e, int init,int fin){
    int mid;
    while(init<fin){
        mid = (init + fin)/2;
        if(h.get(mid) < e){
            init = mid  +1;
        }
        else if (h.get(mid)> e){
            fin = mid -1;
        }
        else{
            return mid;
        }
    }
    return -1;
}

int main(){
    int input;
    cin >> n;
    for(int i = 0 ; i < n ; ++i){
        cin >> input;
        h.add(input);
    }
    h.heapSort();
    //h.deBug();
    cin>>q;
    for(int i = 0 ; i < q ;++i){
        cin>>query;
        int result = binary_search(query,0,n-1);
        if(h.get(result) >= query){
            cout << result + 1 << endl;
        }
        else{
            if(query>h.get(0))
                cout << h.sizeH <<endl;
            else
                cout << 0 <<endl;

        }
    }
    return 0;
}


#include <iostream>
#define MAX_SIZE 1000000
using namespace std;
int n;
int q,query;
struct heap{
    int size,sizeH;
    heap(){
        size = 0 ;
        sizeH = 0;
    }

    int pq[MAX_SIZE];
    int sorted[MAX_SIZE];
    int parent (int leaf) {return (leaf-1)/2;}
    int left (int s) {return s*2 +1;}
    int right (int s) {return s*2 +2;}
    void swap(int *a,int *b){
        int temp = *a;
        *a = *b;
        *b = temp;
    }
    void add (int e){
       int index = size;
       pq[size++] = e;
       while(index>0){
           if (pq[parent(index)]< pq[index])
                swap(&pq[parent(index)],&pq[index]);
           index = parent(index);
       }
    }
    int remove(){
        int index = size--;
        int maior = pq[0];
        pq[0] = pq[index];
        heapfy(0);
        return maior;
    }
    void heapfy(int index){
        while(index<size){
            int s = index;
            int l = left(index);
            int r = right(index);
            if(pq[index]< pq[l]){
                index = l;
            }
            if(pq[index]<pq[r]){
                index = r;
            }
            if (index == s)
                break;
            swap(&pq[index],&pq[parent(index)]);
        }
    }
    bool isEmpty(){
        return size ==0;
    }
    void heapSort(){
        while(!isEmpty()){
            sorted[size] =  remove();
            sizeH++;
        }
    }
    void deBug(){
        for(int i = 0 ; i < sizeH ; i++){
            cout << sorted[i] << " ";
        }
        cout <<endl;
    }
};
struct heap h;
int binarySearch2(int x,int l, int r)
{

    if (r >= l) {

        int mid = l + (r - l) / 2;

        // If the element is present at the middle

        // itself

        if (h.sorted[mid] == x)

            return mid;

        // If element is smaller than mid, then

        // it can only be present in left subarray

        if (h.sorted[mid] > x)

            return binarySearch2(x, l, mid - 1);

        // Else the element can only be present

        // in right subarray

        return binarySearch2(x,mid + 1, r);

    }

    // We reach here when element is not

    // present in array

    return -1;
}
int binary_search(int e, int init,int fin){
    int mid;
    while(init<fin){
        mid = (init + fin)/2;
        if(h.get(mid) < e){
            init = mid  +1;
        }
        else if (h.get(mid)> e){
            fin = mid -1;
        }
        else{
            return mid;
        }
    }
    return -1;
}

int main(){
    int input;
    cin >> n;
    for(int i = 0 ; i < n ; ++i){
        cin >> input;
        h.add(input);
    }
    h.heapSort();
    //h.deBug();
    cin>>q;
    for(int i = 0 ; i < q ;++i){
        cin>>query;
        int result = binarySearch2(query,0,n-1);
        if(h.sorted[result] >= query){
            cout << result + 1 << endl;
        }
        else
                cout << 0 <<endl;
    }
    return 0;
}


#include <iostream>
#define MAX_SIZE 1000000
using namespace std;
int n;
int q,query;
struct heap{
    int size,sizeH;
    heap(){
        size = 0 ;
        sizeH = 0;
    }

    int pq[MAX_SIZE];
    int sorted[MAX_SIZE];
    int parent (int leaf) {return (leaf-1)/2;}
    int left (int s) {return s*2 +1;}
    int right (int s) {return s*2 +2;}
    void swap(int *a,int *b){
        int temp = *a;
        *a = *b;
        *b = temp;
    }
    void add (int e){
       int index = size;
       pq[size++] = e;
       while(index>0){
           if (pq[parent(index)]< pq[index])
                swap(&pq[parent(index)],&pq[index]);
           index = parent(index);
       }
    }
    int remove(){
        int index = size--;
        int maior = pq[0];
        pq[0] = pq[index];
        heapfy(0);
        return maior;
    }
    void heapfy(int index){
        while(index<size){
            int s = index;
            int l = left(index);
            int r = right(index);
            if(pq[index]< pq[l]){
                index = l;
            }
            if(pq[index]<pq[r]){
                index = r;
            }
            if (index == s)
                break;
            swap(&pq[index],&pq[parent(index)]);
        }
    }
    bool isEmpty(){
        return size ==0;
    }
    void heapSort(){
        while(!isEmpty()){
            sorted[size] =  remove();
            sizeH++;
        }
    }
    void deBug(){
        for(int i = 0 ; i < sizeH ; i++){
            cout << sorted[i] << " ";
        }
        cout <<endl;
    }
    int get(int e){
        return sorted[e];
    }
};
struct heap h;
int binary_search(int e, int init,int fin){
    int mid;
    while(init<fin){
        mid = (init + fin)/2;
        if(h.get(mid) < e){
            init = mid  +1;
        }
        else if (h.get(mid)> e){
            fin = mid -1;
        }
        else{
            return mid;
        }
    }
    return -1;
}

int main(){
    int input;
    cin >> n;
    for(int i = 0 ; i < n ; ++i){
        cin >> input;
        h.add(input);
    }
    h.heapSort();
    //h.deBug();
    cin>>q;
    for(int i = 0 ; i < q ;++i){
        cin>>query;
        int result = binary_search(query,0,n-1);
        if(h.get(result) >= query){
            cout << result + 1 << endl;
        }
                cout << 0 <<endl;

        }
    }
    return 0;
}


#include <iostream>
#define MAX_SIZE 1000000
using namespace std;
int n;
int q,query;
struct heap{
    int size,sizeH;
    heap(){
        size = 0 ;
        sizeH = 0;
    }

    int pq[MAX_SIZE];
    int sorted[MAX_SIZE];
    int parent (int leaf) {return (leaf-1)/2;}
    int left (int s) {return s*2 +1;}
    int right (int s) {return s*2 +2;}
    void swap(int *a,int *b){
        int temp = *a;
        *a = *b;
        *b = temp;
    }
    void add (int e){
       int index = size;
       pq[size++] = e;
       while(index>0){
           if (pq[parent(index)]< pq[index])
                swap(&pq[parent(index)],&pq[index]);
           index = parent(index);
       }
    }
    int remove(){
        int index = size--;
        int maior = pq[0];
        pq[0] = pq[index];
        heapfy(0);
        return maior;
    }
    void heapfy(int index){
        while(index<size){
            int s = index;
            int l = left(index);
            int r = right(index);
            if(pq[index]< pq[l]){
                index = l;
            }
            if(pq[index]<pq[r]){
                index = r;
            }
            if (index == s)
                break;
            swap(&pq[index],&pq[parent(index)]);
        }
    }
    bool isEmpty(){
        return size ==0;
    }
    void heapSort(){
        while(!isEmpty()){
            sorted[size] =  remove();
            sizeH++;
        }
    }
    void deBug(){
        for(int i = 0 ; i < sizeH ; i++){
            cout << sorted[i] << " ";
        }
        cout <<endl;
    }
    int get(int e){
        return sorted[e];
    }
};
struct heap h;
int binary_search(int e, int init,int fin){
    int mid;
    while(init<fin){
        mid = (init + fin)/2;
        if(h.get(mid) < e){
            init = mid  +1;
        }
        else if (h.get(mid)> e){
            fin = mid -1;
        }
        else{
            return mid;
        }
    }
    return -1;
}

int main(){
    int input;
    cin >> n;
    for(int i = 0 ; i < n ; ++i){
        cin >> input;
        h.add(input);
    }
    h.heapSort();
    //h.deBug();
    cin>>q;
    for(int i = 0 ; i < q ;++i){
        cin>>query;
        int result = binary_search(query,0,n-1);
        if(h.get(result) >= query){
            cout << result + 1 << endl;
        }
        else
                cout << 0 <<endl;

    }
    return 0;
}


#include <iostream>
#define MAXSIZE 1000002
using namespace std;

int cost[MAXSIZE];
int aux[MAXSIZE];
void merge(int init,int mid, int fin){
	int i = init, k = init , j =mid+1;
	while(i <= mid && j <= fin){
		if(cost[i] < cost[j])
			aux[k++] = cost[i++];
		else
			aux[k++] = cost[j++];
	}
	while(i <= mid)
		aux[k++] = cost[i++];
	while(j <= fin)
		aux[k++] = cost[j++];
	for(int p = init ; p <= fin ;++p)
		cost[p] = aux[p];
}
void mergeSort(int init,int fin){
	int mid = (init + fin)/2.0;
	if(init < fin){
		mergeSort(init,mid);
		mergeSort(mid+1,fin);
		merge(init,mid,fin);
	}
}
void search(int q,int first,int last){
   int middle = (first+last)/2;

while (first <= last) {

  if (cost[middle] < q)
  {
     first = middle + 1;    }
  else if (cost[middle] == q) {

     break;
  }
  else
  {
     last = middle - 1;
  }

  middle = (first + last)/2;
 }
  printf("%d\n",middle+1);
}

int main (){
	int n,m,q;
	scanf("%d",&n);
	for(int i = 0 ; i<n; i++){
		scanf("%d",&cost[i]);
	}
	mergeSort(0,n-1);
	//for(int i = 0 ; i<n; i++)
	//	printf("%d ",cost[i]);
	//printf("\n");
	scanf("%d",&m);
	for(int i = 0 ; i<m; i++){
		scanf("%d",&q);
		//printf("%d\n",q);
	if(q<cost[0])
		printf("0\n");
	else if(q==cost[0])
		printf("1\n");
	else if(q>=cost[n-1])
		printf("%d\n",n);
	else
		search(q,0,n-1);
	}
	return 0;
}


#include <iostream>
#define MAXSIZE 1000002
using namespace std;

int cost[MAXSIZE];
int aux[MAXSIZE];
void merge(int init,int mid, int fin){
	int i = init, k = init , j =mid+1;
	while(i <= mid && j <= fin){
		if(cost[i] < cost[j])
			aux[k++] = cost[i++];
		else
			aux[k++] = cost[j++];
	}
	while(i <= mid)
		aux[k++] = cost[i++];
	while(j <= fin)
		aux[k++] = cost[j++];
	for(int p = init ; p <= fin ;++p)
		cost[p] = aux[p];
}
void mergeSort(int init,int fin){
	int mid = (init + fin)/2.0;
	if(init < fin){
		mergeSort(init,mid);
		mergeSort(mid+1,fin);
		merge(init,mid,fin);
	}
}
void search(int q,int l,int r){
	int paid = 0;
	int mid =-1;
	while (l<=r){
		mid = (l+r)/2;
		if(q < cost[mid]){
			r = mid - 1;
		}
		else if (q >= cost[mid]){
			if(mid == r || cost[mid+1]>q){
				paid = mid+1;
				break;
			}
			else{
				l = mid+1;
			}
		}
	}
	printf("%d\n",paid);
}

int main (){
	int n,m,q;
	scanf("%d",&n);
	for(int i = 0 ; i<n; i++){
		scanf("%d",&cost[i]);
	}
	mergeSort(0,n-1);
	for(int i = 0 ; i<n; i++)
		printf("%d ",cost[i]);
	printf("\n");
	scanf("%d",&m);
	for(int i = 0 ; i<m; i++){
		scanf("%d",&q);
		//printf("Procurar :%d\n",q);
		search(q,0,n-1);
	}
	return 0;
}


#include <iostream>
#define MAXSIZE 1000002
using namespace std;

int cost[MAXSIZE];
int aux[MAXSIZE];
void merge(int init,int mid, int fin){
	int i = init, k = init , j =mid+1;
	while(i <= mid && j <= fin){
		if(cost[i] < cost[j])
			aux[k++] = cost[i++];
		else
			aux[k++] = cost[j++];
	}
	while(i <= mid)
		aux[k++] = cost[i++];
	while(j <= fin)
		aux[k++] = cost[j++];
	for(int p = init ; p <= fin ;++p)
		cost[p] = aux[p];
}
void mergeSort(int init,int fin){
	int mid = (init + fin)/2.0;
	if(init < fin){
		mergeSort(init,mid);
		mergeSort(mid+1,fin);
		merge(init,mid,fin);
	}
}
void search(int q,int l,int r){
	int paid = 0;
	int mid =-1;
	while (l<=r){
		mid = (l+r)/2;
		if(q < cost[mid]){
			r = mid - 1;
		}
		else if (q >= cost[mid]){
			if(mid == r || cost[mid+1]>q){
				paid = mid+1;
				break;
			}
			else{
				l = mid+1;
			}
		}
	}
	printf("%d\n",paid);
}

int main (){
	int n,m,q;
	scanf("%d",&n);
	for(int i = 0 ; i<n; i++){
		scanf("%d",&cost[i]);
	}
	mergeSort(0,n-1);
	//for(int i = 0 ; i<n; i++)
	//	printf("%d ",cost[i]);
	//printf("\n");
	scanf("%d",&m);
	for(int i = 0 ; i<m; i++){
		scanf("%d",&q);
		//printf("Procurar :%d\n",q);
		search(q,0,n-1);
	}
	return 0;
}


#include <iostream>
#define MAX_SIZE 1000000
using namespace std;
struct heap{
    int size,sizeH;
    heap(){
        size = 0 ;
        sizeH = 0;
    }

    int pq[MAX_SIZE];
    int sorted[MAX_SIZE];
    int parent (int leaf) {return (leaf-1)/2;}
    int left (int s) {return s*2 +1;}
    int right (int s) {return s*2 +2;}
    void swap(int *a,int *b){
        int temp = *a;
        *a = *b;
        *b = temp;
    }
    void add (int e){
       int index = size;
       pq[size++] = e;
       while(index>0){
           if (pq[parent(index)]< pq[index])
                swap(&pq[parent(index)],&pq[index]);
           index = parent(index);
       }
    }
    int remove(){
        int index = size--;
        int maior = pq[0];
        pq[0] = pq[index];
        heapfy(0);
        return maior;
    }
    void heapfy(int index){
        while(index<size){
            int s = index;
            int l = left(index);
            int r = right(index);
            if(pq[index]< pq[l]){
                index = l;
            }
            if(pq[index]<pq[r]){
                index = r;
            }
            if (index == s)
                break;
            swap(&pq[index],&pq[parent(index)]);
        }
    }
    bool isEmpty(){
        return size ==0;
    }
    void heapSort(){
        while(!isEmpty()){
            sorted[size-1] =  remove();
            sizeH++;
        }
    }
    void deBug(){
        for(int i = 0 ; i < sizeH ; i++){
            cout << sorted[i] << " ";
        }
        cout <<endl;
    }
};
struct heap h;
int binarySearch2(int x,int l, int r)
{

    if (r >= l) {

        int mid = l + (r - l) / 2;

        // If the element is present at the middle

        // itself

        if (h.sorted[mid] == x)

            return mid;

        // If element is smaller than mid, then

        // it can only be present in left subarray

        if (h.sorted[mid] > x)

            return binarySearch2(x, l, mid - 1);

        // Else the element can only be present

        // in right subarray

        return binarySearch2(x,mid + 1, r);

    }

    // We reach here when element is not

    // present in array

    return -1;
}
int binary_search(int e, int init,int fin){
    int mid;
    while(init<fin){
        mid = (init + fin)/2;
        if(h.sorted[mid] < e){
            init = mid  +1;
        }
        else if (h.sorted[mid]> e){
            fin = mid -1;
        }
        else{
            return mid;
        }
    }
    return -1;
}

int main(){
	int n;
	int q,query;
    int input;
    cin >> n;
    for(int i = 0 ; i < n ; ++i){
        cin >> input;
        h.add(input);
    }
    h.heapSort();
    //h.deBug();
    cin>>q;
    for(int i = 0 ; i < q ;++i){
        cin>>query;
        int result = binarySearch2(query,0,n-1);
        if(h.sorted[result] >= query){
            cout << result + 1 << endl;
        }
        else
			cout << 0 <<endl;
    }
    return 0;
}


#include <iostream>
#define MAX_SIZE 1000000
using namespace std;
int n;
int q,query;
struct heap{
    int size,sizeH;
    heap(){
        size = 0 ;
        sizeH = 0;
    }

    int pq[MAX_SIZE];
    int sorted[MAX_SIZE];
    int parent (int leaf) {return (leaf-1)/2;}
    int left (int s) {return s*2 +1;}
    int right (int s) {return s*2 +2;}
    void swap(int *a,int *b){
        int temp = *a;
        *a = *b;
        *b = temp;
    }
    void add (int e){
       int index = size;
       pq[size++] = e;
       while(index>0){
           if (pq[parent(index)]< pq[index])
                swap(&pq[parent(index)],&pq[index]);
           index = parent(index);
       }
    }
    int remove(){
        int index = size--;
        int maior = pq[0];
        pq[0] = pq[index];
        heapfy(0);
        return maior;
    }
    void heapfy(int index){
        while(index<size){
            int s = index;
            int l = left(index);
            int r = right(index);
            if(pq[index]< pq[l]){
                index = l;
            }
            if(pq[index]<pq[r]){
                index = r;
            }
            if (index == s)
                break;
            swap(&pq[index],&pq[parent(index)]);
        }
    }
    bool isEmpty(){
        return size ==0;
    }
    void heapSort(){
        while(!isEmpty()){
            sorted[size] =  remove();
            sizeH++;
        }
    }
    void deBug(){
        for(int i = 0 ; i < sizeH ; i++){
            cout << sorted[i] << " ";
        }
        cout <<endl;
    }
};
struct heap h;
int binarySearch2(int x,int l, int r)
{

    if (r >= l) {

        int mid = l + (r - l) / 2;

        // If the element is present at the middle

        // itself

        if (h.sorted[mid] == x)

            return mid;

        // If element is smaller than mid, then

        // it can only be present in left subarray

        if (h.sorted[mid] > x)

            return binarySearch2(x, l, mid - 1);

        // Else the element can only be present

        // in right subarray

        return binarySearch2(x,mid + 1, r);

    }

    // We reach here when element is not

    // present in array

    return -1;
}
int binary_search(int e, int init,int fin){
    int mid;
    while(init<fin){
        mid = (init + fin)/2;
        if(h.sorted[mid] < e){
            init = mid  +1;
        }
        else if (h.sorted[mid]> e){
            fin = mid -1;
        }
        else{
            return mid;
        }
    }
    return -1;
}

int main(){
    int input;
    cin >> n;
    for(int i = 0 ; i < n ; ++i){
        cin >> input;
        h.add(input);
    }
    h.heapSort();
    //h.deBug();
    cin>>q;
    for(int i = 0 ; i < q ;++i){
        cin>>query;
        int result = binarySearch2(query,0,n-1);
        if(h.sorted[result-1] >= query){
            cout << result << endl;
        }
        else
                cout << 0 <<endl;
    }
    return 0;
}


#include <iostream>
#define MAX_SIZE 1000000
using namespace std;
int n;
int q,query;
struct heap{
    int size,sizeH;
    heap(){
        size = 0 ;
        sizeH = 0;
    }

    int pq[MAX_SIZE];
    int sorted[MAX_SIZE];
    int parent (int leaf) {return (leaf-1)/2;}
    int left (int s) {return s*2 +1;}
    int right (int s) {return s*2 +2;}
    void swap(int *a,int *b){
        int temp = *a;
        *a = *b;
        *b = temp;
    }
    void add (int e){
       int index = size;
       pq[size++] = e;
       while(index>0){
           if (pq[parent(index)]< pq[index])
                swap(&pq[parent(index)],&pq[index]);
           index = parent(index);
       }
    }
    int remove(){
        int index = size--;
        int maior = pq[0];
        pq[0] = pq[index];
        heapfy(0);
        return maior;
    }
    void heapfy(int index){
        while(index<size){
            int s = index;
            int l = left(index);
            int r = right(index);
            if(pq[index]< pq[l]){
                index = l;
            }
            if(pq[index]<pq[r]){
                index = r;
            }
            if (index == s)
                break;
            swap(&pq[index],&pq[parent(index)]);
        }
    }
    bool isEmpty(){
        return size ==0;
    }
    void heapSort(){
        while(!isEmpty()){
            sorted[size] =  remove();
            sizeH++;
        }
    }
    void deBug(){
        for(int i = 0 ; i < sizeH ; i++){
            cout << sorted[i] << " ";
        }
        cout <<endl;
    }
    int get(int e){
        return sorted[e];
    }
};
struct heap h;
int binarySearch2(int x,int l, int r)
{

    if (r >= l) {

        int mid = l + (r - l) / 2;

        // If the element is present at the middle

        // itself

        if (h.sorted[mid] == x)

            return mid;

        // If element is smaller than mid, then

        // it can only be present in left subarray

        if (h.sorted[mid] > x)

            return binarySearch2(x, l, mid - 1);

        // Else the element can only be present

        // in right subarray

        return binarySearch2(x,mid + 1, r);

    }

    // We reach here when element is not

    // present in array

    return -1;
}
int binary_search(int e, int init,int fin){
    int mid;
    while(init<fin){
        mid = (init + fin)/2;
        if(h.get(mid) < e){
            init = mid  +1;
        }
        else if (h.get(mid)> e){
            fin = mid -1;
        }
        else{
            return mid;
        }
    }
    return -1;
}

int main(){
    int input;
    cin >> n;
    for(int i = 0 ; i < n ; ++i){
        cin >> input;
        h.add(input);
    }
    h.heapSort();
    //h.deBug();
    cin>>q;
    for(int i = 0 ; i < q ;++i){
        cin>>query;
        int result = binarySearch2(query,0,n-1);
        if(h.get(result) >= query){
            cout << result + 1 << endl;
        }
        else
                cout << 0 <<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n,q,a[2000000],b[100000000],e;
int arrsum(int x){
    long long sum=0;
    for (int i=1; i<=x; i++)
    {
        sum+=b[i];
    }
    return sum;
}

int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    cin>>q;
    for (int i=1; i<=q; i++)
    {
        cin>>e;
        cout<<arrsum(e)<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n,q,a[2000000],b[10000000],e;
int arrsum(int x){
    long long sum=0;
    for (int i=1; i<=x; i++)
    {
        sum+=b[i];
    }
    return sum;
}

int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    cin>>q;
    for (int i=1; i<=q; i++)
    {
        cin>>e;
        cout<<arrsum(e)<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n,q,a[2000000],b[2000000],e;
int arrsum(int x){
    int sum=0;
    for (int i=1; i<=x; i++)
    {
        sum+=b[i];
    }
    return sum;
}

int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    cin>>q;
    for (int i=1; i<=q; i++)
    {
        cin>>e;
        cout<<arrsum(e)<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n,q,a[200000],b[200000];
int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    sort(a+1,a+1+n);
    cin>>q;
    for (int i=1; i<=q; i++)
    {
        cin>>b[i];
        int j=n;
        if (b[i]<a[1]) cout<<"0\n";
        else
        {
            while (b[i]<a[j]) j--;
            cout<<j<<"\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n,q,a[2000000],e;
int bs(int l, int r, int x){
    int pivot=(l+r)/2;
    if (x>=a[pivot]&&x<a[pivot+1]) return pivot;
    if (x>=a[pivot]&&pivot==r) return pivot;
    if (x>=a[pivot]) return bs(pivot+1,r,x);
    if (x<=a[pivot]) return bs(l,pivot-1,x);
    return 0;
}

int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    sort(a+1,a+1+n);
    cin>>q;
    for (int i=1; i<=q; i++)
    {
        cin>>e;
        cout<<bs(1,n,e)<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n,q,a[100001],b[100000000],e;
int arrsum(int x){
    int sum=0;
    for (int i=1; i<=x; i++)
    {
        sum+=b[i];
    }
    return sum;
}

int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    cin>>q;
    for (int i=1; i<=q; i++)
    {
        cin>>e;
        cout<<arrsum(e)<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n,q,a[10000],b[100000];
int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    sort(a+1,a+1+n);
    cin>>q;
    for (int i=1; i<=q; i++)
    {
        cin>>b[i];
    }
    for (int i=1; i<=q; i++)
    {
        for (int j=n; j>0; j--)
        {
            if (b[i]>=a[j])
            {
                cout<<j<<"\n";
                break;
            }
            if (b[i]<a[1])
            {
                cout<<"0\n";
                break;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n,q,a[100000],b[1000000];
int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    sort(a+1,a+1+n);
    cin>>q;
    for (int i=1; i<=q; i++)
    {
        cin>>b[i];
    }
    for (int i=1; i<=q; i++)
    {
        for (int j=n; j>0; j--)
        {
            if (b[i]>=a[j])
            {
                cout<<j<<"\n";
                break;
            }
            if (b[i]<a[1])
            {
                cout<<"0\n";
                break;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n,q,a[2000000],b[2000000],e;
int arrsum(int x){
    long long sum=0;
    for (int i=1; i<=x; i++)
    {
        sum+=b[i];
    }
    return sum;
}

int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    cin>>q;
    for (int i=1; i<=q; i++)
    {
        cin>>e;
        cout<<arrsum(e)<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long n,q,a[2000000],b[2000000];
int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    sort(a+1,a+1+n);
    cin>>q;
    for (int i=1; i<=q; i++)
    {
        cin>>b[i];
        for (int j=n; j>0; j--)
        {
            if (b[i]>=a[j])
            {
                cout<<j<<"\n";
                break;
            }
            if (b[i]<a[1])
            {
                cout<<"0\n";
                break;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long n,q,a[2000000],b[2000000];
int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    sort(a+1,a+1+n);
    cin>>q;
    for (int i=1; i<=q; i++)
    {
        cin>>b[i];
    }
    for (int i=1; i<=q; i++)
    {
        for (int j=n; j>0; j--)
        {
            if (b[i]>=a[j])
            {
                cout<<j<<"\n";
                break;
            }
            if (b[i]<a[1])
            {
                cout<<"0\n";
                break;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n,q,a[200000],b[200000];
int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    sort(a+1,a+1+n);
    cin>>q;
    for (int i=1; i<=q; i++)
    {
        cin>>b[i];
        for (int j=n; j>0; j--)
        {
            if (b[i]>=a[j])
            {
                cout<<j<<"\n";
                break;
            }
            if (b[i]<a[1])
            {
                cout<<"0\n";
                break;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define maxn 200005
#define endl '\n'
#define pb push_back
map<int,int>cnt;
int x[maxn];
int main(){
	ios_base::sync_with_stdio(0);
	ll n,m;
	while(cin>>n>>m){
		f(n){
			cin>>x[i];
			cnt[x[i]]++;
		}
		int r=0;
		f(m){
			int x1,x2,y;
			cin>>x1>>x2>>y;
			if(x1==1){
				cnt[x2]--;
				r++;
			}
		}
		int cc=r,ans=r;
		for(auto p:cnt){
			if(p.first>=1000000000)continue;
			cc+=p.second;
			ans=min(ans,cc);
		}
		cout<<ans<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define maxn 200005
#define endl '\n'
#define pb push_back
int cont[maxn];
int suf[maxn];
int main(){
	ios_base::sync_with_stdio(0);
	ll n,m;
	while(cin>>n>>m){
		ms(suf);
		ms(cont);
		f(n){
			cin>>cont[i];
		}
		sort(cont,cont+n);
		f(m){
			int x1,x2,y;
			cin>>x1>>x2>>y;
			if(x1!=1){
				continue;
			}
			else{
				if(x2<cont[0]){
					continue;
				}
				else{
					int k=upper_bound(cont,cont+n,x2)-cont;
					k--;
					suf[k]++;
				}
			}
		}
		for(int i=n;i>=0;i--){
			suf[i]+=suf[i+1];
		}
		int ans=min(m,n);
		for(int i=0;i<=n;i++){
			ans=min(ans,i+suf[i]);
		}
		cout<<ans<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define maxn 200005
#define endl '\n'
#define pb push_back
map<int,int>cnt;
int x[maxn];
int main(){
	ios_base::sync_with_stdio(0);
	ll n,m;
	while(cin>>n>>m){
		f(n){
			cin>>x[i];
			cnt[x[i]]++;
		}
		int r=0;
		f(m){
			int x1,x2,y;
			cin>>x1>>x2>>y;
			if(x1==1){
				cnt[x2]--;
				r++;
			}
		}
		int cc=r,ans=r;
		for(auto p:cnt){
			if(p.first>=100000000)continue;
			cc+=p.second;
			ans=min(ans,cc);
		}
		cout<<ans<<endl;
	}
}


#include <bits/stdc++.h>

using namespace std;

constexpr int MAX_N = 100100;

int n, m;
int vert[MAX_N];
vector<int> horiz;

int main() {
    scanf(" %d %d", &n, &m);
    for (int i = 0; i < n; ++i) {
        scanf(" %d", &vert[i]);
    }

    ++n;
    vert[n - 1] = 1e9;

    for (int i = 0; i < m; ++i) {
        int u, v, w;
        scanf(" %d %d %d", &u, &v, &w);
        if (u == 1) {
            horiz.push_back(v);
        }
    }

    if (horiz.empty()) {
        printf("0\n");
        return 0;
    }

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

    sort(vert, vert + n);

    int best = 200500;
    for (int i = 0; i < n; ++i) {
        // leave all columns starting at i

        int col = vert[i];

        if (horiz[0] >= col) {
            best = min(best, i + (int) horiz.size());
            continue;
        }

        int lo = 0, hi = horiz.size();
        while (lo + 1 < hi) {
            int mid = (lo + hi) / 2;
            if (horiz[mid] < col) {
                lo = mid;
            } else {
                hi = mid;
            }
        }

        best = min(best, i + ((int) horiz.size() - hi));
    }

    printf("%d\n", best);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

constexpr int MAX_N = 100100;

int n, m;
int vert[MAX_N];
vector<int> horiz;

int main() {
    scanf(" %d %d", &n, &m);
    for (int i = 0; i < n; ++i) {
        scanf(" %d", &vert[i]);
    }

    ++n;
    vert[n - 1] = 1e9;

    for (int i = 0; i < m; ++i) {
        int u, v, w;
        scanf(" %d %d %d", &u, &v, &w);
        if (u == 1) {
            horiz.push_back(v);
        }
    }

    if (m == 0) {
        printf("0\n");
        return 0;
    }

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

    sort(vert, vert + n);

    int best = 200500;
    for (int i = 0; i < n; ++i) {
        // leave all columns starting at i

        int col = vert[i];

        if (horiz[0] >= col) {
            best = min(best, i + (int) horiz.size());
            continue;
        }

        int lo = 0, hi = horiz.size();
        while (lo + 1 < hi) {
            int mid = (lo + hi) / 2;
            if (horiz[mid] < col) {
                lo = mid;
            } else {
                hi = mid;
            }
        }

        best = min(best, i + ((int) horiz.size() - hi));
    }

    printf("%d\n", best);

    return 0;
}


#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define TRAV(i, a) for(auto &i : a)
#define SZ(i) ((int)(i).size())
#define X first
#define Y second
#define PR std::pair
#define PII std::pair<int, int>
#define MP std::make_pair
#define ll long long
#define VI std::vector<int>

int n, m;
VI vert, hor;

bool check(int k){
	FOR(i, k){
		if(vert[i] > hor[SZ(hor)-k+i]) return true;
	}
	return false;
}

int main(){
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0);
	std::cin >> n >> m;
	FOR(i, n){
		int a;
		std::cin >> a;
		vert.push_back(a);
	}
	FOR(i, m){
		int a, b, y;
		std::cin >> a >> b >> y;
		if(a == 1) hor.push_back(b);
	}
	bool xd = false;
	FOR(i, SZ(hor)) if(hor[i] != 1000000000) xd = true;
	if(!xd){
		std::cout << SZ(hor) << "\n";
		return 0;
	}
	if(SZ(vert) == 0 || hor.back() < vert[0]){
		std::cout << 0 << "\n";
		return 0;
	}
	std::sort(vert.begin(), vert.end());
	std::sort(hor.begin(), hor.end());
	int left = 0;
	int right = std::min(SZ(vert), SZ(hor))+1;
	while(left < right){
		int mid = (left+right)/2;
		if(check(mid)) right = mid-1;
		else left = mid+1;
	}
	std::cout << left-1 << "\n";
	return 0;
}


#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define TRAV(i, a) for(auto &i : a)
#define SZ(i) ((int)(i).size())
#define X first
#define Y second
#define PR std::pair
#define PII std::pair<int, int>
#define MP std::make_pair
#define ll long long
#define VI std::vector<int>

int n, m;
VI vert, hor;

bool check(int k){
	if(k >= SZ(vert)) return true;
	if(vert[k] > hor[SZ(hor)-1]) return true;
	FOR(i, k){
		if(vert[i] > (SZ(hor)-1-k+i < 0 ? 0 : hor[SZ(hor)-1-k+i])) return true;
	}
	return false;
}

int main(){
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0);
	std::cin >> n >> m;
	FOR(i, n){
		int a;
		std::cin >> a;
		vert.push_back(a);
	}
	FOR(i, m){
		int a, b, y;
		std::cin >> a >> b >> y;
		if(a == 1) hor.push_back(b);
	}
	bool xd = false;
	FOR(i, SZ(hor)) if(hor[i] != 1000000000) xd = true;
	if(!xd){
		std::cout << SZ(hor) << "\n";
		return 0;
	}
	if(SZ(vert) == 0 || hor.back() < vert[0]){
		std::cout << 0 << "\n";
		return 0;
	}
	std::sort(vert.begin(), vert.end());
	std::sort(hor.begin(), hor.end());
	int left = 0;
	int right = std::min(SZ(vert), SZ(hor))+1;
	while(left < right){
		int mid = (left+right)/2;
		if(check(mid)) right = mid-1;
		else left = mid+1;
	}
	if(!check(left)) left++;
	std::cout << std::min((int)std::min(SZ(vert), SZ(hor)), left) << "\n";
	return 0;
}


#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define TRAV(i, a) for(auto &i : a)
#define SZ(i) ((int)(i).size())
#define X first
#define Y second
#define PR std::pair
#define PII std::pair<int, int>
#define MP std::make_pair
#define ll long long
#define VI std::vector<int>

int n, m;
VI vert, hor;

bool check(int k){
	if(k >= SZ(vert) || k >= SZ(hor)) return true;
	//if(k >= SZ(vert)) return true;
	if(vert[k] > hor[SZ(hor)-1]) return true;
	FOR(i, k){
		if(vert[i] > (SZ(hor)-1-k+i < 0 ? 0 : hor[SZ(hor)-1-k+i])) return true;
	}
	return false;
}

int main(){
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0);
	std::cin >> n >> m;
	FOR(i, n){
		int a;
		std::cin >> a;
		vert.push_back(a);
	}
	FOR(i, m){
		int a, b, y;
		std::cin >> a >> b >> y;
		if(a == 1) hor.push_back(b);
	}
	std::sort(vert.begin(), vert.end());
	std::sort(hor.begin(), hor.end());
	bool xd = false;
	FOR(i, SZ(hor)) if(hor[i] != 1000000000) xd = true;
	if(!xd){
		std::cout << SZ(hor) << "\n";
		return 0;
	}
	if(SZ(vert) == 0 || hor.back() < vert[0]){
		std::cout << 0 << "\n";
		return 0;
	}
	int left = 0;
	int right = std::min(SZ(vert), SZ(hor))+1;
	while(left < right){
		int mid = (left+right)/2;
		if(check(mid)) right = mid-1;
		else left = mid+1;
	}
	if(!check(left)) left++;
	std::cout << std::min((int)std::min(SZ(vert), SZ(hor)), left) << "\n";
	return 0;
}


// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 100000, M = 100000;

int xx[N + 1], rr[M];

int main() {
	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> xx[i];
	xx[n] = 1000000000;
	sort(xx, xx + n + 1);
	int m_ = 0;
	for (int j = 0; j < m; j++) {
		int l, r, y; cin >> l >> r >> y;
		if (l == 1)
			rr[m_++] = r;
	}
	m = m_;
	sort(rr, rr + m);
	int ans = n + m;
	for (int i = 0, j = 0; i <= n; i++) {
		while (j < m && rr[j] < xx[i])
			j++;
		ans = min(ans, i + m - j);
	}
	cout << ans << '\n';
	return 0;
}


/*************************************************************************
    > File Name: A.cpp
    > Author: Roundgod
    > Mail: wcysai@foxmail.com
    > Created Time: 2018-11-07 22:08:47
 ************************************************************************/

#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,m;
vector<int> v;
int d[MAXN];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
    {
        int x;scanf("%d",&x);
        v.push_back(x);
    }
    v.push_back(0);v.push_back(INF);
    sort(v.begin(),v.end());
    for(int i=0;i<m;i++)
    {
        int x1,x2,y;
        scanf("%d%d%d",&x1,&x2,&y);
        int l=lower_bound(v.begin(),v.end(),x1-1)-v.begin();
        int r=upper_bound(v.begin(),v.end(),x2)-v.begin()-1;
        if(l>r) continue;
        d[l+1]++;d[r+1]--;
    }
    for(int i=1;i<=n+1;i++) d[i]+=d[i-1];
    int ans=INF;
    for(int i=1;i<=n+1;i++) ans=min(ans,i-1+d[i]);
    printf("%d\n",ans);
    return 0;
}


/*************************************************************************
    > File Name: A.cpp
    > Author: Roundgod
    > Mail: wcysai@foxmail.com
    > Created Time: 2018-11-07 22:08:47
 ************************************************************************/

#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,m;
vector<int> v;
int d[MAXN];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
    {
        int x;scanf("%d",&x);
        v.push_back(x);
    }
    v.push_back(0);v.push_back(INF);
    sort(v.begin(),v.end());
    for(int i=0;i<m;i++)
    {
        int x1,x2,y;
        scanf("%d%d%d",&x1,&x2,&y);
        if(x1!=1) continue;
        int r=upper_bound(v.begin(),v.end(),x2)-v.begin()-1;
        d[1]++;d[r+1]--;
    }
    for(int i=1;i<=n+1;i++) d[i]+=d[i-1];
    int ans=INF;
    for(int i=1;i<=n+1;i++) ans=min(ans,i-1+d[i]);
    printf("%d\n",ans);
    return 0;
}


/*************************************************************************
    > File Name: A.cpp
    > Author: Roundgod
    > Mail: wcysai@foxmail.com
    > Created Time: 2018-11-07 22:08:47
 ************************************************************************/

#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,m;
vector<int> v;
int d[MAXN];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
    {
        int x;scanf("%d",&x);
        v.push_back(x);
    }
    v.push_back(0);
    sort(v.begin(),v.end());
    for(int i=0;i<m;i++)
    {
        int x1,x2,y;
        scanf("%d%d%d",&x1,&x2,&y);
        int l=lower_bound(v.begin(),v.end(),x1-1)-v.begin();
        int r=upper_bound(v.begin(),v.end(),x2)-v.begin();
        d[l]++;d[r]--;
    }
    for(int i=1;i<=n;i++) d[i]+=d[i-1];
    int ans=INF;
    for(int i=1;i<=n;i++) ans=min(ans,(i-1)+d[i]);
    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7;
int a[N],b[N];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int x,y,z;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=m;i++){
        scanf("%d%d%d",&x,&y,&z);
        if(x!=1){i--,m--;}
        else b[i]=y;
    }
    sort(a,a+1+n);
    sort(b+1,b+1+m);
    int p=lower_bound(b+1,b+1+n,a[1])-b;
    int ans=m-p+1;
    for(int i=1;i<=n;i++){
        p=lower_bound(b+1,b+1+n,a[i]+1)-b;
        ans=min(ans,m-p+i+1);
    }
    int tmp=0;
    for(int i=1;i<=m;i++){
        if(b[i]==(int)1e9) tmp++;
    }
    ans=min(ans,tmp+n);
    printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7;
const int maxn=1e9;
int a[N],b[N];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int x,y,z;
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=m;i++){
        scanf("%d%d%d",&x,&y,&z);
        if(x!=1){i--,m--;}
        else b[i]=y;
    }
    sort(a,a+1+n);
    sort(b+1,b+1+m);
    int ans=maxn;
    for(int i=1;i<=n;i++){
        int p=lower_bound(b+1,b+1+m,a[i])-b;
        ans=min(ans,m-p+i);
    }
    int tmp=0;
    for(int i=1;i<=m;i++){
        if(b[i]==maxn) tmp++;
    }
    ans=min(ans,tmp+n);
    printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7;
const int maxn=1e9;
int a[N],b[N];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int x,y,z;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=m;i++){
        scanf("%d%d%d",&x,&y,&z);
        if(x!=1){i--,m--;}
        else b[i]=y;
    }
    sort(a,a+1+n);
    sort(b+1,b+1+m);
    int ans=maxn*3;
    for(int i=1;i<=n;i++){
        int p=lower_bound(b+1,b+1+n,a[i])-b;
        ans=min(ans,m-p+i);
    }
    int tmp=0;
    for(int i=1;i<=m;i++){
        if(b[i]==maxn) tmp++;
    }
    ans=min(ans,tmp+n);
    printf("%d\n",ans);
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cunbidun
 */

#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define watch(x) out << (#x) << " = " << (x) << endl
#define rf(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rb(i, b, a) for(int (i) = (b); (i) >= (a); (i)--)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;

const int N = 2e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 2e9;

class Task1074A {
public:
    void solve(istream &in, ostream &out) {
        int n, m;
        in >> n >> m;
        vi a(n);
        rf(i, 0, n - 1) in >> a[i];
        a.pb(1e9);
        sort(all(a));
        vi b;
        rf(i, 0, m - 1) {
            int x1, x2, y;
            in >> x1 >> x2 >> y;
            if (x1 == 1) b.pb(x2);
        }
        sort(all(b));
        int p = 0;
        int ans = INF;
//        rf(i, 0, sz(b) - 1) if (b[i] >= a[0])ans++;

        rf(i, 0, sz(a) - 1) {
            while (p < sz(b) && b[p] < a[i]) p++;
            ans = min(ans, i + sz(b) - p);
        }
        out << ans << "\n";
    }
};

class TestCase {
public:
    static constexpr int numTest = 0;
    static constexpr bool haveAns = false;

    static void generateTest(ostream &test) {
    }

    static void solve(istream &in, ostream &out) {
    }
};

class Checker {
public:
    static constexpr double arg = 0.0;

    static bool check(istream &in, istream &out) {
    }
};

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    Task1074A solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    out << fixed << setprecision(10);
    solver.solve(in, out);
    return 0;
}


#include <bits/stdc++.h>
#include <ctime>

using namespace std;

#define ALL(x) x.begin(), x.end()
#define bits(x) __builtin_popcount(x)
#define bitsll(x) __builtin_popcountll(x)
#define precision(a) fixed << setprecision(a)

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef vector <int> vi;

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

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

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

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

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

template <class T1, class T2>
inline T1 min (const T1 & x, const T2 & y) {
	return x < (T1) y ? x : (T1) y;
}

template <class T1, class T2>
inline T1 max (T1 & x, const T2 & y) {
	return x > (T1) y ? x : (T1) y;
}

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

struct _flag_t {
	string val;
};
const _flag_t _1d{", "}, _2d{"\n  "};
_flag_t _flag_d = _1d;
_flag_t _flag = _1d;

ostream & operator<< (ostream & os, _flag_t flag) {
	_flag = flag;
	return os;
}

template <class Os, class It>
Os & _out (Os & os, It f, It l) {
	if (f == l) return os << "{}";
	_flag_t cur_flag = _flag;
	os << _flag_d << "{ " << *f++;
	for (; f != l; os << cur_flag.val << *f++);
	return os << " }";
}

template <class Os, class T>
auto operator<< (Os & os, const T & v) -> decltype(begin(v), end(v), os) {return _out(os, begin(v), end(v));}

template <class Os, class T, size_t N>
auto operator<< (Os & os, const array <T, N> & v) -> decltype(begin(v), end(v), os) {return _out(os, begin(v), end(v));}

template <size_t I = 0, bool B = false, class Os, class T>
auto _out_tuple (Os & os, const T & tup) -> typename enable_if <(I == 0), Os &>::type {
	return os << get <I>(tup) << (B ? ", " : "");
}

template <size_t I = 0, bool B = false, class Os, class T>
auto _out_tuple (Os & os, const T & tup) -> typename enable_if <(I > 0), Os &>::type {
	return _out_tuple <I - 1, true>(os, tup) << get <I>(tup) << (B ? ", " : "");
}

template <class Os, class T>
auto operator<< (Os & os, const T & tup) -> decltype(get <tuple_size <T>::value - 1>(tup), os) {
	return os << "[", _out_tuple <tuple_size <T>::value - 1>(os, tup) << "]";
}

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

int n, m;
vector <int> v;
vector <int> h;
int ans;

int f (int border) {
	auto it = upper_bound(ALL(h), border - 1);
	return h.size() - ((int) (it - h.begin()));
}

int main () {
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		v.push_back(x);
	}

	for (int i = 1; i <= m; i++) {
		int x1, x2, y;
		cin >> x1 >> x2 >> y;
		if (x1 != 1) {
			continue;
		}
		h.push_back(x2);
	}

	if (h.empty()) {
		cout << 0;
		return 0;
	}
	sort(ALL(h));

	sort(ALL(v));
	if (v.empty() || v.back() != 1e9) {
		v.push_back(1e9);
	}
	v.push_back(2e9);

	ans = f(v[0]);
	for (int i = 1; i < n; i++) {
		eqMin(ans, f(v[i]) + i);
	}
	cout << ans;
}


#include <bits/stdc++.h>
#include <ctime>

using namespace std;

#define ALL(x) x.begin(), x.end()
#define bits(x) __builtin_popcount(x)
#define bitsll(x) __builtin_popcountll(x)
#define precision(a) fixed << setprecision(a)

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef vector <int> vi;

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

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

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

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

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

template <class T1, class T2>
inline T1 min (const T1 & x, const T2 & y) {
	return x < (T1) y ? x : (T1) y;
}

template <class T1, class T2>
inline T1 max (T1 & x, const T2 & y) {
	return x > (T1) y ? x : (T1) y;
}

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

struct _flag_t {
	string val;
};
const _flag_t _1d{", "}, _2d{"\n  "};
_flag_t _flag_d = _1d;
_flag_t _flag = _1d;

ostream & operator<< (ostream & os, _flag_t flag) {
	_flag = flag;
	return os;
}

template <class Os, class It>
Os & _out (Os & os, It f, It l) {
	if (f == l) return os << "{}";
	_flag_t cur_flag = _flag;
	os << _flag_d << "{ " << *f++;
	for (; f != l; os << cur_flag.val << *f++);
	return os << " }";
}

template <class Os, class T>
auto operator<< (Os & os, const T & v) -> decltype(begin(v), end(v), os) {return _out(os, begin(v), end(v));}

template <class Os, class T, size_t N>
auto operator<< (Os & os, const array <T, N> & v) -> decltype(begin(v), end(v), os) {return _out(os, begin(v), end(v));}

template <size_t I = 0, bool B = false, class Os, class T>
auto _out_tuple (Os & os, const T & tup) -> typename enable_if <(I == 0), Os &>::type {
	return os << get <I>(tup) << (B ? ", " : "");
}

template <size_t I = 0, bool B = false, class Os, class T>
auto _out_tuple (Os & os, const T & tup) -> typename enable_if <(I > 0), Os &>::type {
	return _out_tuple <I - 1, true>(os, tup) << get <I>(tup) << (B ? ", " : "");
}

template <class Os, class T>
auto operator<< (Os & os, const T & tup) -> decltype(get <tuple_size <T>::value - 1>(tup), os) {
	return os << "[", _out_tuple <tuple_size <T>::value - 1>(os, tup) << "]";
}

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

int n, m;
vector <int> v;
vector <int> h;
int ans;

int f (int border) {
	auto it = upper_bound(ALL(h), border - 1);
	return h.size() - ((int) (it - h.begin()));
}

int main () {
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		v.push_back(x);
	}

	for (int i = 1; i <= m; i++) {
		int x1, x2, y;
		cin >> x1 >> x2 >> y;
		if (x1 != 1) {
			continue;
		}
		h.push_back(x2);
	}

	if (h.empty()) {
		cout << 0;
		return 0;
	}
	sort(ALL(h));

	sort(ALL(v));
	if (v.empty() || v.back() != 1e9) {
		v.push_back(1e9);
	}
	v.push_back(2e9);

	ans = f(v[0]);
	for (int i = 1; i <= n; i++) {
		eqMin(ans, f(v[i]) + i);
	}
	cout << ans;
}


#include<bits/stdc++.h>

using namespace std;

#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(auto i = (a); i != (b); ++i)
#define REP(i,n) rep(i,0,n)
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int maxn = 1e5;
int N, M;
int X[maxn], Y[maxn];
int nrem[maxn] = {};

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

	cin >> N >> M;
	REP(i, N) cin >> X[i];

	int minR = 1000 * 1000 * 1000;
	X[N++] = minR;

	sort(X, X + N);
	REP(i, N) minR = min(minR, X[i]);

	for (int i = 0; i < M; ) {
		int l, r;
		cin >> l >> r >> Y[i];

		if (l > 1 || r < minR) {
			// we can by-pass this.
			M--;
		} else {
			// blocked by some X[i]

			// l == 1 && r >= minR
			int idx = upper_bound(X, X + N, r) - X;
			assert(idx > 0);
			nrem[idx - 1]++;

			i++;
		}
	}

	int ret = M;
	int nleft = M;
	for (int i = 0; i + 1 < N; i++) {
		nleft -= nrem[i]; // do not bother the horizontal
		nleft++; // break down this vertical
		ret = min(ret, nleft);
	}
	cout << ret << endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(auto i = (a); i != (b); ++i)
#define REP(i,n) rep(i,0,n)
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int maxn = 1e5 + 10;
int N, M;
int X[maxn], Y[maxn];
int nrem[maxn] = {};

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

	cin >> N >> M;
	REP(i, N) cin >> X[i];

	int minR = 1000 * 1000 * 1000;
	X[N++] = minR;

	sort(X, X + N);
	REP(i, N) minR = min(minR, X[i]);

	for (int i = 0; i < M; ) {
		int l, r;
		cin >> l >> r >> Y[i];

		if (l > 1 || r < minR) {
			// we can by-pass this.
			M--;
		} else {
			// blocked by some X[i]

			// l == 1 && r >= minR
			int idx = upper_bound(X, X + N, r) - X;
			//  assert(idx > 0);
			nrem[idx - 1]++;

			i++;
		}
	}

	int ret = M;
	int nleft = M;
	for (int i = 0; i + 1 < N; i++) {
		nleft -= nrem[i]; // do not bother the horizontal
		nleft++; // break down this vertical
		ret = min(ret, nleft);
	}
	cout << ret << endl;

	return 0;
}


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

const int N=100000;
int n,m,y[100001];

int main(){
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)scanf("%d",&y[i]);
    y[n]=1000000000;
    unordered_map<int,vector<pair<int,int>>> horz;
    for(int i=0;i<m;i++){
        int x1,x2,y1;
        scanf("%d%d%d",&x1,&x2,&y1);
        horz[y1].push_back({x1,x2});
    }
    for(auto &h:horz)
        sort(h.second.begin(),h.second.end());
    vector<int> x;
    for(auto &h:horz){
        if(h.second.front().first>1)continue;
        int right=h.second.front().second;
        for(auto &p:h.second){
            if(p.first==right+1)right=p.second;
            else break;
        }
        x.push_back(right);
    }
    sort(x.begin(),x.end());
    int ans=n+m,j=0;
    for(int i=0;i<=n;i++){
        while(j<x.size()&&x[j]<y[i])j++;
        ans=min(ans,i+int(x.size())-j);
    }
    printf("%d\n",ans);
}


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

int n,m,y[100001];

int main(){
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)scanf("%d",&y[i]);
    sort(y,y+n);
    y[n]=1000000000;
    vector<int> x;
    for(int i=0;i<m;i++){
        int x1,x2,y1;
        scanf("%d%d%d",&x1,&x2,&y1);
        if(x1==1)x.push_back(x2);
    }
    sort(x.begin(),x.end());
    int ans=m,j=0;
    for(int i=0;i<=n;i++){
        while(j<x.size()&&x[j]<y[i])j++;
        ans=min(ans,i+int(x.size())-j);
    }
    printf("%d\n",ans);
}


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

const int N=100000;
int n,m,y[100001];

int main(){
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)scanf("%d",&y[i]);
    y[n]=1000000000;
    vector<int> x;
    for(int i=0;i<m;i++){
        int x1,x2,y1;
        scanf("%d%d%d",&x1,&x2,&y1);
        if(x1==1)x.push_back(x2);
    }
    sort(x.begin(),x.end());
    int ans=n+m,j=0;
    for(int i=0;i<=n;i++){
        while(j<x.size()&&x[j]<y[i])j++;
        ans=min(ans,i+int(x.size())-j);
    }
    printf("%d\n",ans);
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;

const int N = 1e5 + 7;

int vs[N];

int d[N];
int y[N];

set<pii> need;
set<int> broke;
vector<int> added[N];
vector<int> deled[N];

void solve(){
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i){
        cin>> vs[i];
        vs[i]--;
    }
    sort(vs, vs + n);
    for (int i = 0; i < m; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        y[i] = c;
        auto ia = upper_bound(vs, vs + n, a) - vs;
        auto ib = upper_bound(vs, vs + n, b) - vs;
        if (ia == ib) continue;
        if (a == 0) broke.insert(i);
        else added[ia].push_back(i);
        deled[ib].push_back(i);
    }
    int ans = m + n;
    for (int i = 0; i <= n; ++i){
        for (auto & el : added[i])
            need.insert({y[el], el});
        for (auto & el : deled[i]){
            if (broke.count(el) == 0) continue;
            broke.erase(el);
            int cy = y[el];
            auto it = need.lower_bound({cy + 1, -1});
            if (it != need.end()){
                broke.insert(it->second);
                need.erase(it);
            }
        }
        ans = min(ans, (int)broke.size() + i);
    }
    cout << ans;
}

int main(int argc, char *argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (argc >= 2) freopen(argv[1], "r", stdin);
    if (argc >= 3) freopen(argv[2], "w", stdout);
    solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;

const int N = 1e5 + 7;

int vs[N];

int d[N];
int y[N];

set<pii> need;
set<int> broke;
vector<int> added[N];
vector<int> deled[N];

void solve(){
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i){
        cin>> vs[i];
        vs[i]--;
    }
    sort(vs, vs + n);
    for (int i = 0; i < m; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        y[i] = c;
        auto ia = upper_bound(vs, vs + n, a) - vs;
        auto ib = upper_bound(vs, vs + n, b) - vs;

        if (b == (int)1e9-1) ib++;
        if (ia == ib) continue;
        if (a == 0) broke.insert(i);
        else added[ia].push_back(i);
        deled[ib].push_back(i);
    }
    int ans = m + n;
    for (int i = 0; i <= n; ++i){
        for (auto & el : added[i])
            need.insert({y[el], el});
        for (auto & el : deled[i]){
            if (broke.count(el) == 0) continue;
            broke.erase(el);
            int cy = y[el];
            auto it = need.lower_bound({cy + 1, -1});
            if (it != need.end()){
                broke.insert(it->second);
                need.erase(it);
            }
        }
        ans = min(ans, (int)broke.size() + i);
    }
    cout << ans;
}

int main(int argc, char *argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (argc >= 2) freopen(argv[1], "r", stdin);
    if (argc >= 3) freopen(argv[2], "w", stdout);
    solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;

const int N = 1e5 + 7;

int vs[N];

int d[N];
int y[N];

set<pii> need;
set<int> broke;
vector<int> added[N];
vector<int> deled[N];

void solve(){
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i){
        cin>> vs[i];
        vs[i]--;
    }
    sort(vs, vs + n);
    for (int i = 0; i < m; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        y[i] = c;
        auto ia = upper_bound(vs, vs + n, a) - vs;
        auto ib = upper_bound(vs, vs + n, b) - vs;

        if (b == (int)1e9-1) ib++;
        if (a == 0) broke.insert(i);
        deled[ib].push_back(i);
    }
    int ans = m + n;
    for (int i = 0; i <= n; ++i){
        for (auto & el : deled[i]){
            if (broke.count(el) == 0) continue;
            broke.erase(el);
        }
        ans = min(ans, (int)broke.size() + i);
    }
    cout << ans;
}

int main(int argc, char *argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (argc >= 2) freopen(argv[1], "r", stdin);
    if (argc >= 3) freopen(argv[2], "w", stdout);
    solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;

const int N = 1e5 + 7;

int vs[N];

int d[N];
int y[N];

set<pii> need;
set<int> broke;
vector<int> added[N];
vector<int> deled[N];

void solve(){
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i){
        cin>> vs[i];
        vs[i]--;
    }
    sort(vs, vs + n);
    for (int i = 0; i < m; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        y[i] = c;
        auto ia = upper_bound(vs, vs + n, a) - vs;
        auto ib = upper_bound(vs, vs + n, b) - vs;

        if (b == (int)1e9-1 && ib == 0) ib++;
        if (ia == ib) continue;
        if (a == 0) broke.insert(i);
        else added[ia].push_back(i);
        deled[ib].push_back(i);
    }
    int ans = m + n;
    for (int i = 0; i <= n; ++i){
        for (auto & el : added[i])
            need.insert({y[el], el});
        for (auto & el : deled[i]){
            if (broke.count(el) == 0) continue;
            broke.erase(el);
            int cy = y[el];
            auto it = need.lower_bound({cy + 1, -1});
            if (it != need.end()){
                broke.insert(it->second);
                need.erase(it);
            }
        }
        ans = min(ans, (int)broke.size() + i);
    }
    cout << ans;
}

int main(int argc, char *argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (argc >= 2) freopen(argv[1], "r", stdin);
    if (argc >= 3) freopen(argv[2], "w", stdout);
    solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

const int MAXN = 1e5 + 7;
const int INF = 1e9 + 7;

int a[MAXN];
vector <int> v;

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

    const int MX = 1000 * 1000 * 1000;

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a + n);
    int add = 0;
    for (int i = 0; i < m; ++i) {
        int l, r, y;
        cin >> l >> r >> y;
        if (l != 1) continue;
        if (r == MX) ++add;
        else v.push_back(r);
    }

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

    int ans = INF;
    for (int i = 0; i < n; ++i) {
        int newans = i + (int)v.size() - (lower_bound(v.begin(), v.end(), a[i]) - v.begin());
        ans = min(ans, newans);
    }
    ans = min(ans, n);

    cout << ans + add << '\n';

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

const int MAXN = 1e5 + 7;
const int INF = 1e9 + 7;

int a[MAXN];
vector <int> v;

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

    const int MX = 1000 * 1000 * 1000;

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a + n);
    int add = 0;
    for (int i = 0; i < m; ++i) {
        int l, r, y;
        cin >> l >> r >> y;
        if (l != 1) continue;
        if (r == MX) ++add;
        else v.push_back(r);
    }

    int ans = INF;
    for (int i = 0; i < n; ++i) {
        int newans = i + (int)v.size() - (lower_bound(v.begin(), v.end(), a[i]) - v.begin());
        ans = min(ans, newans);
    }
    ans = min(ans, n);

    cout << ans + add << '\n';

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
#define ll long long
int n, m, r[maxn], le[maxn];
const int top = 1e9;
int ct = 0, cts;
int upr(int x)
{
    int l = 0, r = ct - 1, ans = 0;
    while (l <= r)
    {
        int mid = (l + r) >> 1;
        if (le[mid] < x) ans = mid + 1, l = mid + 1;
        else r = mid - 1;
    }
    return ans;
}
void input()
{
    cin >> n >> m;
    for (int i = 0; i < n; ++ i)
    {
        cin >> r[i];
    }
    r[n ++] = top;
    sort (r, r + n);
    for (int i = 0, a, b, c; i < m; ++ i)
    {
        cin >> a >> b >> c;
        if (a != 1 or b < r[0]) continue;
        if (b == top) cts ++;
        le[ct ++] = b;
    }
    sort (le, le + ct);
}
void slove()
{
    if (ct == 0)
    {
        cout << 0 << endl;
        return ;
    }
    if (n == 1)
    {
        cout << cts << endl;
        return ;
    }
    int ans = 0x3f3f3f3f;
    for (int i = 0; i < n; ++ i)
    {
        int p = upr(r[i]);
        int cc = ct - p;
        ans = min(ans, i + cc);
    }
    cout << ans << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    input();
    slove();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
#define ll long long
int n, m, r[maxn], le[maxn];
const int top = 1e9;
int ct = 0, ans, cts;
int upr(int x)
{
    int l = 0, r = ct - 1, ans = 0;
    while (l <= r)
    {
        int mid = (l + r) >> 1;
        if (le[mid] < x) ans = mid + 1, l = mid + 1;
        else r = mid - 1;
    }
    return ans;
}
void input()
{
    cin >> n >> m;
    for (int i = 0; i < n; ++ i)
    {
        cin >> r[i];
    }
    sort (r, r + n);
    for (int i = 0, a, b, c; i < m; ++ i)
    {
        cin >> a >> b >> c;
        if (a != 1 or b < r[0]) continue;
        if (b == top) cts ++;
        le[ct ++] = b;
    }
    sort (le, le + ct);
}
void slove()
{
    if (ct == 0)
    {
        cout << 0 << endl;
        return ;
    }
    if (n == 0)
    {
        cout << cts << endl;
        return ;
    }
    int ans = 0x3f3f3f3f;
    for (int i = 0; i < n; ++ i)
    {
        int p = upr(r[i]);
        ans = min(ans, i + ct - p);
    }
    cout << ans << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    input();
    slove();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
#define ll long long
int n, m, r[maxn], le[maxn];
const int top = 1e9;
int ct = 0, ans, cts;
int upr(int x)
{
    int l = 0, r = ct - 1, ans = 0;
    while (l <= r)
    {
        int mid = (l + r) >> 1;
        if (le[mid] < x) ans = mid + 1, l = mid + 1;
        else r = mid - 1;
    }
    return ans;
}
void input()
{
    cin >> n >> m;
    for (int i = 0; i < n; ++ i)
    {
        cin >> r[i];
    }
    sort (r, r + n);
    for (int i = 0, a, b, c; i < m; ++ i)
    {
        cin >> a >> b >> c;
        if (a != 1 or b < r[1]) continue;
        if (b == top) cts ++;
        le[++ ct] = b;
    }
    sort (le, le + ct);
}
void slove()
{
    if (ct == 0)
    {
        cout << 0 << endl;
        return ;
    }
    if (n == 0)
    {
        cout << cts << endl;
        return ;
    }
    int ans = 0x3f3f3f3f;
    for (int i = 0; i < n; ++ i)
    {
        int p = upr(r[i]);
        ans = min(ans, i + ct - p);
    }
    cout << ans << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    input();
    slove();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
#define ll long long
int n, m, r[maxn], le[maxn];
const int top = 1e9;
int ct = 0, ans, cts;
int upr(int x)
{
    int l = 0, r = ct - 1, ans = 0;
    while (l <= r)
    {
        int mid = (l + r) >> 1;
        if (le[mid] < x) ans = mid + 1, l = mid + 1;
        else r = mid - 1;
    }
    return ans;
}
void input()
{
    cin >> n >> m;
    for (int i = 0; i < n; ++ i)
    {
        cin >> r[i];
    }
    sort (r, r + n);
    for (int i = 0, a, b, c; i < m; ++ i)
    {
        cin >> a >> b >> c;
        if (a != 1 or b < r[0]) continue;
        if (b == top) cts ++;
        le[ct ++] = b;
    }
    sort (le, le + ct);
}
void slove()
{
    if (ct == 0)
    {
        cout << 0 << endl;
        return ;
    }
    if (n == 0)
    {
        cout << cts << endl;
        return ;
    }
    int ans = 0x3f3f3f3f;
    for (int i = 0; i < n; ++ i)
    {
        int p = upr(r[i]);
        ans = min(ans, i + ct - p);
    }
    cout << ans << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    input();
    slove();
    return 0;
}
//******


#include<bits/stdc++.h>
using namespace std;
//#define int long long
const int M=1e5+10;
int a[M],b[M],n,mm,m,ans;
map<int,vector<pair<int,int> > >mp;
set<int>s;
int32_t main()
{
  cin>>n>>mm;
  for(int i=1;i<=n;i++)
    scanf("%d",a+i);
  for(int i=1;i<=mm;i++)
    {
      int l,r,y;
      scanf("%d%d%d",&l,&r,&y);
      s.insert(y);
      mp[y].push_back({l,r});
    }
  sort(a+1,a+n+1);
  for(auto y:s)
    {
      vector<pair<int,int> >v=mp[y];
      sort(v.begin(),v.end());
      if(v[0].first!=1)continue;
      b[++m]=v[0].second;
      for(int i=1;i<v.size();i++)
	if(v[i].first<=b[m])
	  b[m]=max(b[i],v[i].second);
    }
  sort(b+1,b+n+1);
  if(a[n]!=1e9)
    {
      n++;
      a[n]=1e9;
    }
  ans=m;
  for(int i=1;i<=n;i++)
    {
      int l=0,r=m+1,mid;
      while(r-l>1)
	{
	  mid=(l+r)/2;
	  if(b[mid]<a[i])
	    l=mid;
	  else
	    r=mid;
	}
      //cout<<m<<" "<<l<<" "<<i<<endl;
      ans=min(ans,m-l+i-1);
    }
  cout<<ans<<endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
//#define int long long
const int M=1e5+10;
int a[M],b[M],n,mm,m,ans;
int32_t main()
{
  cin>>n>>mm;
  for(int i=1;i<=n;i++)
    scanf("%d",a+i);
  for(int i=1;i<=mm;i++)
    {
      int l,r,y;
      scanf("%d%d%d",&l,&r,&y);
      if(l>1)continue;
      b[i]=r;
      m++;
    }
  sort(a+1,a+n+1);
  sort(b+1,b+m+1);
  if(a[n]!=1e9)
    {
      n++;
      a[n]=1e9;
    }
  ans=m;
  for(int i=1;i<=n;i++)
    {
      int l=0,r=m+1,mid;
      while(r-l>1)
	{
	  mid=(l+r)/2;
	  if(b[mid]<a[i])
	    l=mid;
	  else
	    r=mid;
	}
      //cout<<m<<" "<<l<<" "<<i<<endl;
      ans=min(ans,m-l+i-1);
    }
  cout<<ans<<endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
//#define int long long
const int M=1e5+10;
int a[M],b[M],n,mm,m,ans;
map<int,vector<pair<int,int> > >mp;
set<int>s;
int32_t main()
{
  cin>>n>>mm;
  for(int i=1;i<=n;i++)
    scanf("%d",a+i);
  for(int i=1;i<=mm;i++)
    {
      int l,r,y;
      scanf("%d%d%d",&l,&r,&y);
      mp[y].push_back({l,r});
      s.insert(y);
    }
  sort(a+1,a+n+1);
  for(auto y:s)
    {
      vector<pair<int,int> >v=mp[y];
      sort(v.begin(),v.end());
      if(v[0].first!=1)continue;
      m++;
      for(int i=0;i<v.size();i++)
	if(v[i].first-1<=b[m])
	  b[m]=max(b[m],v[i].second);
    }
  sort(b+1,b+n+1);
  if(a[n]!=1e9)
    {
      n++;
      a[n]=1e9;
    }
  ans=m;
  for(int i=1;i<=n;i++)
    {
      int l=0,r=m+1,mid;
      while(r-l>1)
	{
	  mid=(l+r)/2;
	  if(b[mid]<a[i])
	    l=mid;
	  else
	    r=mid;
	}
      //cout<<m<<" "<<l<<" "<<i<<endl;
      ans=min(ans,m-l+i-1);
    }
  cout<<ans<<endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
//#define int long long
const int M=1e5+10;
int a[M],b[M],n,mm,m,ans;
int32_t main()
{
  cin>>n>>mm;
  for(int i=1;i<=n;i++)
    scanf("%d",a+i);
  for(int i=1;i<=mm;i++)
    {
      int l,r,y;
      scanf("%d%d%d",&l,&r,&y);
      if(l>1)continue;
      b[++m]=r;
    }
  sort(a+1,a+n+1);
  sort(b+1,b+m+1);
  if(a[n]!=1e9)
    {
      n++;
      a[n]=1e9;
    }
  ans=m;
  for(int i=1;i<=n;i++)
    {
      int l=0,r=m+1,mid;
      while(r-l>1)
	{
	  mid=(l+r)/2;
	  if(b[mid]<a[i])
	    l=mid;
	  else
	    r=mid;
	}
      //cout<<m<<" "<<l<<" "<<i<<endl;
      ans=min(ans,m-l+i-1);
    }
  cout<<ans<<endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
//#define int long long
const int M=1e5+10;
int a[M],b[M],n,mm,m,ans;
map<int,vector<pair<int,int> > >mp;
set<int>s;
int32_t main()
{
  cin>>n>>mm;
  for(int i=1;i<=n;i++)
    scanf("%d",a+i);
  for(int i=1;i<=mm;i++)
    {
      int l,r,y;
      scanf("%d%d%d",&l,&r,&y);
      s.insert(y);
      mp[y].push_back({l,r});
    }
  sort(a+1,a+n+1);
  for(auto y:s)
    {
      vector<pair<int,int> >v=mp[y];
      sort(v.begin(),v.end());
      if(v[0].first!=1)continue;
      b[++m]=v[0].second;
      for(int i=1;i<v.size();i++)
	if(v[i].first<=b[m])
	  b[m]=max(b[m],v[i].second);
    }
  sort(b+1,b+n+1);
  if(a[n]!=1e9)
    {
      n++;
      a[n]=1e9;
    }
  ans=m;
  for(int i=1;i<=n;i++)
    {
      int l=0,r=m+1,mid;
      while(r-l>1)
	{
	  mid=(l+r)/2;
	  if(b[mid]<a[i])
	    l=mid;
	  else
	    r=mid;
	}
      //cout<<m<<" "<<l<<" "<<i<<endl;
      ans=min(ans,m-l+i-1);
    }
  cout<<ans<<endl;
  return 0;
}


//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int popcount(ll x){return __builtin_popcountll(x);};
int poplow(ll x){return __builtin_ctzll(x);};
int pophigh(ll x){return 63 - __builtin_clzll(x);};

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,m;cin>>n>>m;
  vector<ll>y(n);
  rep(i,0,n)cin>>y[i];
  sort(ALL(y));
  y.PB((ll)1e9);
  vector<ll>x;
  ll add=0;
  rep(i,0,m){
    ll x1,x2,y;cin>>x1>>x2>>y;
    if(x1==1){
      x.PB(x2);
    }
  }
  sort(ALL(x));
  res=INF;
  ll idx=0;
  rep(i,0,n+1){
    while(idx<x.size()&&x[idx]<y[i]){
      idx++;
    }
    chmin(res,(ll)x.size()-idx+i);
  }
  cout<<res<<endl;
  return 0;
}


#include "bits/stdc++.h"
using namespace std;
template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }

int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	vector<int> vert;
	for(auto i = 0; i < n; ++ i){
		int x;
		cin >> x;
		vert.push_back(x);
	}
	sort(vert.begin(), vert.end());
	vert.push_back(1e9);
	vector<int> hori;
	for(auto i = 0; i < m; ++ i){
		int x1, x2, y;
		cin >> x1 >> x2 >> y;
		if(x1 == 1){
			hori.push_back(x2);
		}
	}
	sort(hori.begin(), hori.end());
	int res = m;
	for(auto i = 0, j = 0; i < int(vert.size()); ++ i){
		while(j < int(hori.size()) && hori[j] < vert[i]){
			++ j;
		}
		ctmin(res, i + int(hori.size()) - j);
	}
	cout << res << "\n";
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                //
//                                   Coded by Aeren                                   //
//                                                                                //
////////////////////////////////////////////////////////////////////////////////////////


#include<bits/stdc++.h>

using namespace std;

#define ll long long
const int N = 2e5 + 5;

int n, m, k;
ll a[N], b[N];

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

	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= m; i++) {
		int L, R, y;
		cin >> L >> R >> y;
		if (L == 1 && y < 1e9) {
			b[++k] = R;
		}
	}
	sort(a + 1, a + 1 + n);
	sort(b + 1, b + 1 + k);
	a[n + 1] = 1e9;

	int ans = 1e9;
	for (int i = 1; i <= n + 1; i++) {
		int res = i - 1;
		int id = lower_bound(b + 1, b + 1 + k, a[i]) - b;
		res += k - id + 1;
		ans = min(ans, res);
	}

	cout << ans;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef std::string str;
#define sei set<int>
#define sell set<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vld vector<ld>
#define vstr vector<str>
#define vpii vector<pii>
#define vpll vector<pll>
#define all(v) v.begin(),v.end()
#define foa(i,v) for(auto i : v)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define deb(x)  cerr << #x << " = " << x << endl
#define pb push_back
#define pob pop_back
#define F first
#define S second
#define OK order_of_key
#define FO find_by_order
#define nmax 1000100
const ld PI = 3.141592653589793238462643383279;
const ll inf = std::numeric_limits<ll>::max();
const int infint = std::numeric_limits<int>::max();
const ll mod = 1e9+7;
using namespace __gnu_pbds;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

map<int,vpii> mp;

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

    int n,m;
    cin >> n >> m;
    vi mx,v;
    fo(i,0,n){
        int x;
        cin >> x;
        v.pb(x);
    }
    sort(all(v));
    int ttt = 0;
    fo(i,0,m){
        int x1,x2,y;
        cin >> x1 >> x2 >> y;
        if(x1 == 1 && x2 == 1e9){
            ttt++;
            continue;
        }
        mp[y].pb({x1,x2});
    }
    foa(&i,mp) sort(all(i.S));
    foa(&i,mp){
        if(i.S[0].F == 1) mx.pb(i.S[0].S);
    }
    sort(all(mx));
    if(mx.size() == 0 || v.size() == 0) return cout << ttt,0;
    int ans = mx.size()-(lower_bound(all(mx),v[0])-mx.begin());
    fo(i,1,v.size()){
        ans = min(ans,(int)mx.size()-(lower_bound(all(mx),v[i])-mx.begin())+i);
    }
    cout << min(ans,(int)v.size())+ttt;

    return 0;
}


#ifdef ONPC
# define _GLIBCXX_DEBUG
#define deb(a) cerr << "yo " << #a << " = " << a << endl;
#else
#define deb(a)
#endif
#include <bits/stdc++.h>
#define endl "\n"
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

typedef long long ll;
typedef long double ld;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << fixed << setprecision(20);
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n), b;
    for (int i = 0 ; i < n;i++){
        cin >> a[i];
    }
    for (int i = 0; i < m; i++){
        ll x1, x2, y;
        cin >> x1 >> x2 >> y;
        if (x1 == 1){
            b.push_back(x2);
        }
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    ll ans = INF;
    for (int i = 0; i <= n; i++){
        if (i == n){
            ll kol = lower_bound(b.begin(), b.end(), (ll)1e9) - b.begin();
            kol = (ll)b.size() - kol;
            ans = min(ans, kol + i);
        }
        else {
            ll kol = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
            kol = (ll) b.size() - kol;
            ans = min(ans, kol + i);
        }
    }
    cout << ans;

#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
//egor lox


#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vecll>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),(x)))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),(x)))
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {unsigned long long x;cin>>x;return x;}
string stin() {string s;cin>>s;return s;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
vec iota(int n){vec a(n);iota(all(a),0);return a;}
void print(){putchar(' ');}
void print(bool a){cout<<a;}
void print(int a){cout<<a;}
void print(long long a){cout<<a;}
void print(char a){cout<<a;}
void print(string &a){cout<<a;}
void print(double a){cout<<a;}
template<class T> void print(const vector<T>&);
template<class T, size_t size> void print(const array<T, size>&);
template<class T, class L> void print(const pair<T, L>& p);
template<class T, size_t size> void print(const T (&)[size]);
template<class T> void print(const vector<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ cout<<" "; print(*i); } cout<<endl;}
template<class T> void print(const deque<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ cout<<" "; print(*i); } }
template<class T, size_t size> void print(const array<T, size>& a){ print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ cout<<" "; print(*i); } }
template<class T, class L> void print(const pair<T, L>& p){ cout<<'(';print(p.first); cout<<","; print(p.second);cout<<')'; }
template<class T, size_t size> void print(const T (&a)[size]){ print(a[0]); for(auto i = a; ++i != end(a); ){ cout<<" "; print(*i); } }
template<class T> void print(const T& a){ cout << a; }
int out(){ putchar('\n'); return 0; }
template<class T> int out(const T& t){ print(t); putchar('\n'); return 0; }
template<class Head, class... Tail> int out(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); return 0; }
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
vector<pll> factor(ll x){ vector<pll> ans; for(ll i = 2; i * i <= x; i++) if(x % i == 0){ ans.push_back({i, 1}); while((x /= i) % i == 0) ans.back().second++; } if(x != 1) ans.push_back({x, 1}); return ans; }
vector<int> divisor(int x){ vector<int> ans; for(int i=1;i*i<=x;i++)if(x%i==0){ans.pb(i);if(i*i!=x)ans.pb(x/i);} return ans;}
int popcount(ll x){return __builtin_popcountll(x);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int n){return uniform_int_distribution<int>(0, n)(rng);}
// #define _GLIBCXX_DEBU
#define endl '\n'
#ifdef _MY_DEBUG
    #undef endl
    #define debug(x) cout<<#x<<": "<<x<<endl
    void err(){}
    template<class T> void err(const T& t){ print(t);  cout<<" ";}
    template<class Head, class... Tail> void err(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); }
#else
    #define debug(x)
    template<class... T> void err(const T&...){}
#endif
#pragma endregion

using ar = array<short,4>;
using AR = array<ll,4>;
constexpr ll T[4]={1,1000,1000000,1000000000};
inline ll f(const ar &x,int k){
    ll res=0;
    rep(i,4)res+=T[(i+k)&3]*x[i];
    return res;
}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);cout<<fixed<<setprecision(15);
    int n=in(),m=in();
    vec v;rep(i,n)v.pb(in());
    v.pb(1e9);
    sort(all(v));
    n+=1;
    vec cnt(n+1);
    rep(i,m){
        int l=in(),r=in();in();
        if(l!=1)continue;
        cnt[ub(v,r)]--;
        cnt[0]++;
    }
    rep(i,n)cnt[i+1]+=cnt[i];
    rep(i,n+1)cnt[i]+=i;
    cout << *min_element(cnt.begin(),cnt.begin()+n) << endl;
}


#include <bits/stdc++.h>
#define inf 0x3f3f3f3f

using namespace std;

int a[100005],b[100005];

int main() {
  int n,m;
  scanf("%d%d",&n,&m);
  for(int i=1;i<=n;i++) scanf("%d",&a[i]);
  a[++n]=1e9;
  int cnt=0;
  for(int i=1;i<=m;i++) {
  	int x1,x2,y;
  	scanf("%d%d%d",&x1,&x2,&y);
  	if (x1==1) b[++cnt]=x2;
  }
  sort(a+1,a+n+1);
  sort(b+1,b+cnt+1);
  int r=1,ans=inf;
  for(int i=1;i<=n;i++) {
  	while (r<=cnt&&b[r]<a[i]) r++;
  	ans=min(ans,cnt-r+i);
  }
  printf("%d\n",ans);
  return 0;
}


/* Author haleyk10198 */
/* �@��:  haleyk10198 */
/* CF handle: haleyk100198*/
/* FOR ACM-ICPC WF*/
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

#define pb push_back

constexpr auto MOD = 1000000007LL;
constexpr auto LINF = (1LL << 60);
constexpr auto INF = 2147483647LL;
constexpr auto PI = 3.1415926535897932384626433;
constexpr auto EPS = 1E-9;

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair <T1, T2> p) {
    out << p.first << ' ' << p.second;
    return out;
}

template<typename T1, typename T2>
istream &operator>>(istream &in, pair <T1, T2> &p) {
    in >> p.first >> p.second;
    return in;
}

template<typename T>
istream &operator>>(istream &in, vector <T> &v) {
    for (auto &x: v)
        in >> x;
    return in;
}

template<typename T>
ostream &operator<<(ostream &out, vector <T> v) {
    for (int i = 0; i < v.size(); i++)
        out << v[i] << (i + 1 == v.size() ? '\n' : ' ');
    out.flush();
    return out;
}

#if __cplusplus < 201703L
#define mp make_pair
#endif

#define MAXN 100010

int n, m, a[MAXN], b[MAXN];

int main() {
#ifdef LOCAL
    freopen("../input.txt","r",stdin);
//		freopen("output.txt","w",stdout);
    freopen("../debug.txt", "w", stderr);
#endif
    ios_base::sync_with_stdio(false);

   cin >> n >> m;
   for(int i = 0; i < n; i++)
       cin >> a[i];
   a[n++] = 1e9;

   for(int i = 0, x, y, z; i < m; i++){
       cin >> x >> y >> z;
       if(x != 1){
           i--; m--;
       }
       else{
           b[i] = y;
       }
   }

   sort(a, a+n);
   sort(b, b+m);

   int res = INF;

   for(int i = 0, j = 0; i < n; i++){
        while(j < m && b[j] < a[i])
            j++;
        res = min(res, i+m-j);
   }

   cout << res << endl;

    return 0;
}


/* Author haleyk10198 */
/* �@��:  haleyk10198 */
/* CF handle: haleyk100198*/
/* FOR ACM-ICPC WF*/
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

#define pb push_back

constexpr auto MOD = 1000000007LL;
constexpr auto LINF = (1LL << 60);
constexpr auto INF = 2147483647LL;
constexpr auto PI = 3.1415926535897932384626433;
constexpr auto EPS = 1E-9;

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> p) {
    out << p.first << ' ' << p.second;
    return out;
}

template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
    in >> p.first >> p.second;
    return in;
}

template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
    for (auto &x: v)
        in >> x;
    return in;
}

template<typename T>
ostream &operator<<(ostream &out, vector<T> v) {
    for (int i = 0; i < v.size(); i++)
        out << v[i] << (i + 1 == v.size() ? '\n' : ' ');
    out.flush();
    return out;
}

#if __cplusplus < 201703L
#define mp make_pair
#endif

int l[2], r[2], t[2];

int main() {
#ifdef LOCAL
    freopen("../input.txt","r",stdin);
//		freopen("output.txt","w",stdout);
    freopen("../debug.txt", "w", stderr);
#endif
    ios_base::sync_with_stdio(false);

    for(int i = 0; i < 2; i++)
        cin >> l[i] >> r[i] >> t[i];

    int dd = l[0]-l[1];
    int g = gcd(t[0], t[1]);

    int r1 = min(r[0]-l[0], r[1]-l[1]-(dd+g)%g);
    int r2 = min(r[1]-l[1], r[0]-l[0]+(dd+g)%g);

    cout << max(r1, r2)+1 << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define pb pop_back
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define Sim template<class n
Sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
Sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
Sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
Sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
Sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif

#define I(x) #x " = ", (x), " "
#define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " "

int n, m, res;
vector<int> V, X;

int main()
{
	scanf("%d%d", &n, &m);
	FOR(i, 1, n)
	{
	  int a;
	  scanf("%d", &a);
	  V.PB(a);
	}
	FOR(i, 1, m)
	{
	  int a, b, c;
	  scanf("%d%d%d", &a, &b, &c);
	  if (a != 1)
	  {
	    continue;
	  }
	  X.PB(b);
	}
	V.PB(1000000000);
	sort(ALL(V));
	sort(ALL(X));
	if (SIZ(V) > 1)
	{
	  res = SIZ(V);
	}
	else
	{
	  res = 1e9;
	}
	int tmp = 0, r = 0;
	FOR(i, 0, SIZ(V) - 1)
	{
	  while (tmp < SIZ(X) && X[tmp] < V[i])
	  {
	    tmp++;
	  }
	  res = min(res, r + SIZ(X) - tmp);
	  r++;
	}
	printf("%d\n", res);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define pb pop_back
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define Sim template<class n
Sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
Sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
Sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
Sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
Sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif

#define I(x) #x " = ", (x), " "
#define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " "

int n, m, res;
vector<int> V, X;

int main()
{
	scanf("%d%d", &n, &m);
	FOR(i, 1, n)
	{
	  int a;
	  scanf("%d", &a);
	  V.PB(a);
	}
	FOR(i, 1, m)
	{
	  int a, b, c;
	  scanf("%d%d%d", &a, &b, &c);
	  if (a != 1)
	  {
	    continue;
	  }
	  X.PB(b);
	}
	V.PB(1000000000);
	sort(ALL(V));
	sort(ALL(X));
	if (SIZ(V) > 1)
	{
	  res = SIZ(V) - 1;
	}
	else
	{
	  res = 1e9;
	}
	int tmp = 0, r = 0;
	FOR(i, 0, SIZ(V) - 1)
	{
	  while (tmp < SIZ(X) && X[tmp] < V[i])
	  {
	    tmp++;
	  }
	  res = min(res, r + SIZ(X) - tmp);
	  r++;
	}
	printf("%d\n", res);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define pb pop_back
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define Sim template<class n
Sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
Sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
Sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
Sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
Sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif

#define I(x) #x " = ", (x), " "
#define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " "

int n, m, res = 1e9;
vector<int> V, X;

int main()
{
	scanf("%d%d", &n, &m);
	FOR(i, 1, n)
	{
	  int a;
	  scanf("%d", &a);
	  V.PB(a);
	}
	FOR(i, 1, m)
	{
	  int a, b, c;
	  scanf("%d%d%d", &a, &b, &c);
	  if (a != 1)
	  {
	    continue;
	  }
	  X.PB(b);
	}
	V.PB(1000000000);
	sort(ALL(V));
	sort(ALL(X));
	int tmp = 0, r = 0;
	FOR(i, 0, SIZ(V) - 1)
	{
	  while (tmp < SIZ(X) && X[tmp] < V[i])
	  {
	    tmp++;
	  }
	  res = min(res, r + SIZ(X) - tmp);
	  r++;
	}
	printf("%d\n", res);
	return 0;
}


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

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

  int n, m;
  cin >> n >> m;

  int last = 1000 * 1000 * 1000;

  vector<int> a(n);
  for (auto& x : a) cin >> x;
  sort(a.begin(), a.end());

  vector<int> b;
  b.reserve(m);
  for (int i = 0; i < m; ++i) {
    int l, r, y;
    cin >> l >> r >> y;
    if (y == last || 1 < l) continue;
    if (a.size() && r < a[0]) continue;
    b.emplace_back(r);
  }

  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());

  int ans = b.size();
  for (int i = 0; i < n; ++i) {
    int x = a[i];
    while (b.size() && b.back() < x) b.pop_back();
    if (i + 1 == n)
      while (b.size() && b.back() != last) b.pop_back();
    ans = min(ans, int(b.size()) + i + 1);
  }
  cout << ans;
}


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

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

  int n, m;
  cin >> n >> m;

  int last = 1000 * 1000 * 1000;

  vector<int> a(n);
  for (auto& x : a) cin >> x;
  sort(a.begin(), a.end());

  int rem = 0;

  vector<int> b;
  b.reserve(m);
  for (int i = 0; i < m; ++i) {
    int l, r, y;
    cin >> l >> r >> y;
    if (y == last) continue;
    if (1 < l) continue;
    if (r == last) {
      ++rem;
    } else {
      b.emplace_back(r);
    }
  }

  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());

  int ans = b.size();
  for (int i = 0; i < n; ++i) {
    auto x = a[i];
    while (b.size() && b.back() < x) b.pop_back();
    if (i + 1 == n) b.resize(0);
    ans = min(ans, int(b.size()) + i);
  }
  ans = min(ans, int(b.size()) + n);
  cout << ans + rem;
}


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

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

  int n, m;
  cin >> n >> m;

  vector<int> a(n);
  for (auto& x : a) cin >> x;
  sort(a.begin(), a.end());

  int last = 1000 * 1000 * 1000;
  vector<int> b;
  b.reserve(m);
  for (int i = 0; i < m; ++i) {
    int l, r, y;
    cin >> l >> r >> y;
    if (y == last || 1 < l || r < a[0]) continue;
    b.emplace_back(r);
  }

  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());

  int ans = b.size();
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    cnt++;
    int x = a[i];
    while (b.size() && b.back() < x) b.pop_back();
    if (i + 1 == n)
      while (b.size() && b.back() != last) b.pop_back();
    ans = min(ans, int(b.size()) + cnt);
  }
  cout << ans;
}


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

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

  int n, m;
  cin >> n >> m;

  int last = 1000 * 1000 * 1000;

  vector<int> a(n + 1);
  for (int i = 0; i < n; ++i) cin >> a[i];
  a[n] = 2 * last;
  sort(a.begin(), a.end());

  vector<int> b;
  b.reserve(m);
  for (int i = 0; i < m; ++i) {
    int l, r, y;
    cin >> l >> r >> y;
    if (y == last || 1 < l || r < a[0]) continue;
    b.emplace_back(r);
  }

  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());

  int ans = b.size();
  for (int i = 0; i < n; ++i) {
    int x = a[i];
    while (b.size() && b.back() < x) b.pop_back();
    if (i + 1 == n)
      while (b.size() && b.back() != last) b.pop_back();
    ans = min(ans, int(b.size()) + i + 1);
  }
  cout << ans;
}


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

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

  int n, m;
  cin >> n >> m;

  int last = 1000 * 1000 * 1000;

  vector<int> a(n);
  for (auto& x : a) cin >> x;
  sort(a.begin(), a.end());

  int rem = 0;

  vector<int> b;
  b.reserve(m);
  for (int i = 0; i < m; ++i) {
    int l, r, y;
    cin >> l >> r >> y;
    if (y == last) continue;
    if (1 < l) continue;
    if (r == last) {
      ++rem;
    } else {
      b.emplace_back(r);
    }
  }

  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());

  int ans = b.size();
  for (int i = 0; i < n; ++i) {
    auto x = a[i];
    while (b.size() && b.back() < x) b.pop_back();
    ans = min(ans, int(b.size()) + i);
    if (i + 1 == n) b.resize(0);
  }
  ans = min(ans, int(b.size()) + n);
  cout << ans + rem;
}


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

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

  int n, m;
  cin >> n >> m;

  int last = 1000 * 1000 * 1000;

  vector<int> a(n);
  for (auto& x : a) cin >> x;
  sort(a.begin(), a.end());
  a.emplace_back(2 * last);

  int rem = 0;

  vector<int> b;
  b.reserve(m + 1);
  for (int i = 0; i < m; ++i) {
    int l, r, y;
    cin >> l >> r >> y;
    if (1 < l) continue;
    if (r == last) {
      ++rem;
    } else {
      b.emplace_back(r);
    }
  }

  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());

  int ans = a.size() + b.size();
  for (int i = 0; i <= n; ++i) {
    auto x = a[i];
    while (b.size() && b.back() < x) b.pop_back();
    ans = min(ans, int(b.size()) + i);
  }
  cout << ans + rem;
}