#include <bits/stdc++.h>

using namespace std;

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

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

#define MAX 100000

vector<int> vert, hori;

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

  int n, m, in;

  cin >> n >> m;

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

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

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

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

  int atual=0, min=INF;

  for( int i=0; i<vert.size(); i++ ){
    while( atual < hori.size() && hori[atual] < vert[i] ){
      atual++;
    }
    if( min > i + hori.size() - atual ){
      min = i + hori.size() - atual;
    }
  }

  cout << min << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

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

#define MAX 100000

vector<int> vert, hori;

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

  int n, m, in;

  cin >> n >> m;

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

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

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

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

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

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

  resp += numh;

  cout << resp << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

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

#define MAX 100000

vector<int> vert, hori;

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

  int n, m, in;

  cin >> n >> m;

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

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

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

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

  int atualv=0, atualh=0, cu=0, next, resp=0;

  while( vert[atualv] > hori[atualh] ){
    atualh++;
  }

  atualv = 1;
  next = atualh;

  while( atualv < vert.size() && next < hori.size() ){
    while( vert[atualv] > hori[next] ){
      next++;
      if( next == hori.size() ){
        break;
      }
    }
    if( next-atualh > cu ){
      resp += cu+1;
      atualh = next;
      cu=0;
    }else{
      cu++;
    }
    atualv++;
  }

  resp += hori.size()-atualh;

  cout << resp << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

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

#define MAX 100000

vector<int> vert, hori;

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

  int n, m, in;

  cin >> n >> m;

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

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

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

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

  int atualv=0, atualh=0, cu=0, next, resp=0;

  while( vert[atualv] > hori[atualh] ){
    atualh++;
  }

  atualv = 1;
  next = atualh;

  while( atualv < vert.size() && next < hori.size() ){
    while( vert[atualv] > hori[next] ){
      next++;
      if( next == hori.size() ){
        goto end;
      }
    }
    if( next-atualh > cu ){
      resp += cu+1;
      atualh = next;
      cu=0;
    }else{
      cu++;
    }
    atualv++;
  }

  end:

  resp += hori.size()-atualh;

  cout << resp << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

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

#define MAX 100000

vector<int> vert, hori;

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

  int n, m, in;

  cin >> n >> m;

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

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

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

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

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

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

  resp += numh;

  cout << resp << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

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

#define MAX 100000

vector<int> vert, hori;

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

  int n, m, in;

  cin >> n >> m;

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

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

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

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

  int atualv=0, atualh=0, cu=0, next, resp=0;

  while( vert[atualv] > hori[atualh] ){
    atualh++;
    if( atualh == hori.size() ){
      cout << 0 << endl;
      return 0;
    }
  }

  atualv = 1;
  next = atualh;

  while( atualv < vert.size() && next < hori.size() ){
    while( vert[atualv] > hori[next] ){
      next++;
      if( next == hori.size() ){
        break;
      }
    }
    if( next-atualh > cu ){
      resp += cu+1;
      atualh = next;
      cu=0;
    }else{
      cu++;
    }
    atualv++;
  }

  resp += hori.size()-atualh;

  cout << resp << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

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

#define MAX 100000

vector<int> vert, hori;

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

  int n, m, in;

  cin >> n >> m;

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

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

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

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

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

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

  resp += numh;

  cout << resp << endl;

  return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#define MAXN 100000

using namespace std;

typedef struct line {
	int x1, x2, y;
};

int N, M;
int v[MAXN + 1];
line h[MAXN + 1];
int bigger[MAXN + 1];
int irrelevant[MAXN + 1];

bool asc(line i, line j) {
	return i.x2 < j.x2;
}

int main() {
	cin >> N >> M;
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> h[i].x1 >> h[i].x2 >> h[i].y;
		if (h[i].x2 == 1000000000)		cnt++;
	}

	int ans = 0x7FFFFFFF;
	sort(v, v + N);
	sort(h, h + M, asc);
	int start = M - 1;

	int index = 0;
	for (int i = M - 1; i >= 0; i--) {
		if (h[i].x1 != 1) {
			index++;
		}
		irrelevant[i] = index;
	}
	irrelevant[M] = 0;

	for (int i = N - 1; i >= 0; i--) {
		for (int j = start; j >= 0; j--) {
			if (h[j].x2 < v[i]) {
				bigger[i] = M - j - 1 - irrelevant[j + 1];
				start = j;
				break;
			}
			else if (j == 0) {
				bigger[i] = M - j - irrelevant[j + 1];
				start = j;
				break;
			}
		}
	}

	for (int i = 0; i < N; i++) {
		ans = min(ans, bigger[i] + i);
	}

	ans = min(N + cnt, ans);
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#define MAXN 100000

using namespace std;

typedef struct line {
	int x1, x2, y;
};

int N, M;
int v[MAXN + 1];
line h[MAXN + 1];
int bigger[MAXN + 1];
int irrelevant[MAXN + 1];

bool asc(line i, line j) {
	return i.x2 < j.x2;
}

int main() {
	cin >> N >> M;
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> h[i].x1 >> h[i].x2 >> h[i].y;
		if (h[i].x2 == 1000000000)		cnt++;
	}

	int ans = 0x7FFFFFFF;
	sort(v, v + N);
	sort(h, h + M, asc);
	int start = M - 1;

	int index = 0;
	for (int i = M - 1; i >= 0; i--) {
		if (h[i].x1 != 1) {
			index++;
		}
		irrelevant[i] = index;
	}
	irrelevant[M] = 0;

	for (int i = N - 1; i >= 0; i--) {
		for (int j = start; j >= 0; j--) {
			if (h[j].x2 < v[i]) {
				bigger[i] = M - j - 1 - irrelevant[j + 1];
				start = j;
				break;
			}
			else if (j == 0) {
				bigger[i] = M - j - irrelevant[j];
				start = j;
				break;
			}
		}
	}

	for (int i = 0; i < N; i++) {
		ans = min(ans, bigger[i] + i);
	}

	ans = min(N + cnt, ans);
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#define MAXN 100000

using namespace std;

typedef struct line {
	int x1, x2, y;
};

int N, M;
int v[MAXN + 1];
line h[MAXN + 1];
int bigger[MAXN + 1];
int irrelevant[MAXN + 1];

bool asc(line i, line j) {
	return i.x2 < j.x2;
}

int main() {
	cin >> N >> M;
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> h[i].x1 >> h[i].x2 >> h[i].y;
		if (h[i].x2 == 1000000000)		cnt++;
	}

	int ans = 0x7FFFFFFF;
	sort(v, v + N);
	sort(h, h + M, asc);
	int start = M - 1;

	int index = 0;
	for (int i = M - 1; i >= 0; i--) {
		if (h[i].x1 != 1) {
			index++;
		}
		irrelevant[i] = index;
	}
	irrelevant[M] = 0;

	for (int i = N - 1; i >= 0; i--) {
		for (int j = start; j >= 0; j--) {
			if (h[j].x2 < v[i]) {
				bigger[i] = M - j - 1 - irrelevant[j];
				start = j;
				break;
			}
			else if (j == 0) {
				bigger[i] = M - j - irrelevant[j];
				start = j;
				break;
			}
		}
	}

	for (int i = 0; i < N; i++) {
		ans = min(ans, bigger[i] + i);
	}

	ans = min(N + cnt, ans);
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#define MAXN 100000

using namespace std;

typedef struct line {
	int x1, x2, y;
};

int N, M;
int v[MAXN + 1];
line h[MAXN + 1];
int bigger[MAXN + 1];

bool asc(line i, line j) {
	return i.x2 < j.x2;
}

int main() {
	cin >> N >> M;
	int cnt1 = 0;
	int cnt2 = 0;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> h[i].x1 >> h[i].x2 >> h[i].y;
		if (h[i].x1 == 1)		cnt1++;
		if (h[i].x2 == 1000000000)		cnt2++;
	}

	int ans = 0x7FFFFFFF;
	sort(v, v + N);
	sort(h, h + M, asc);
	int start = M - 1;
	int irrelevant = 0;
	for (int i = N - 1; i >= 0; i--) {
		for (int j = start; j >= 0; j--) {
			if (h[j].x1 != 1)
				irrelevant++;
			if (h[j].x2 < v[i]) {
				bigger[i] = M - j - 1 - irrelevant;
				start = j;
				break;
			}
			else if (j == 0) {
				start = j;
				bigger[i] = M - j - irrelevant;
				break;
			}
		}
	}

	for (int i = 0; i < N; i++) {
		ans = min(ans, bigger[i] + i);
	}
	cnt1 = min(cnt1, N + cnt2);
	ans = min(cnt1, ans);
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#define MAXN 100000

using namespace std;

typedef struct line {
	int x1, x2, y;
};

int N, M;
int v[MAXN + 1];
line h[MAXN + 1];
int bigger[MAXN + 1];

bool asc(line i, line j) {
	return i.x2 < j.x2;
}

int main() {
	cin >> N >> M;
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> h[i].x1 >> h[i].x2 >> h[i].y;
		if (h[i].x2 == 1000000000)		cnt++;
	}

	int ans = 0x7FFFFFFF;
	sort(v, v + N);
	sort(h, h + M, asc);
	int start = M - 1;
	int irrelevant = 0;
	for (int i = N - 1; i >= 0; i--) {
		for (int j = start; j >= 0; j--) {
			if (h[j].x1 != 1 && h[j].x2 < v[i])
				irrelevant++;
			if (h[j].x2 < v[i]) {
				bigger[i] = max(0, M - j - 1 - irrelevant);
				start = j;
				break;
			}
			else if (j == 0) {
				bigger[i] = M - j - irrelevant;
				start = j;
				break;
			}
		}
	}

	for (int i = 0; i < N; i++) {
		ans = min(ans, bigger[i] + i);
	}

	ans = min(N + cnt, ans);
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#define MAXN 100000

using namespace std;

typedef struct line {
	int x1, x2, y;
};

int N, M;
int v[MAXN + 1];
line h[MAXN + 1];
int bigger[MAXN + 1];
int irrelevant[MAXN + 1];

bool asc(line i, line j) {
	return i.x2 < j.x2;
}

int main() {
	cin >> N >> M;
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> h[i].x1 >> h[i].x2 >> h[i].y;
		if (h[i].x2 == 1000000000)		cnt++;
	}

	int ans = 0x7FFFFFFF;
	sort(v, v + N);
	sort(h, h + M, asc);
	int start = M - 1;

	int index = 0;
	for (int i = M - 1; i >= 0; i--) {
		if (h[i].x1 == 0) {
			index++;
		}
		irrelevant[i] = index;
	}
	irrelevant[M] = 0;

	for (int i = N - 1; i >= 0; i--) {
		for (int j = start; j >= 0; j--) {
			if (h[j].x2 < v[i]) {
				bigger[i] = M - j - 1 - irrelevant[j + 1];
				start = j;
				break;
			}
			else if (j == 0) {
				bigger[i] = M - j - irrelevant[j + 1];
				start = j;
				break;
			}
		}
	}

	for (int i = 0; i < N; i++) {
		ans = min(ans, bigger[i] + i);
	}

	ans = min(N + cnt, ans);
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#define MAXN 100000

using namespace std;

typedef struct line {
	int x1, x2, y;
};

int N, M;
int v[MAXN + 1];
line h[MAXN + 1];
int bigger[MAXN + 1];

bool asc(line i, line j) {
	return i.x2 < j.x2;
}

int main() {
	cin >> N >> M;
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> h[i].x1 >> h[i].x2 >> h[i].y;
		if (h[i].x2 == 1000000000)		cnt++;
	}

	int ans = 0x7FFFFFFF;
	sort(v, v + N);
	sort(h, h + M, asc);
	int start = M - 1;
	int irrelevant = 0;
	int notyet = 0;
	for (int i = N - 1; i >= 0; i--) {
		for (int j = start; j >= 0; j--) {
			if (h[j].x1 != 1)
				notyet++;
			if (h[j].x2 < v[i])
				irrelevant = notyet;
			if (h[j].x2 < v[i]) {
				bigger[i] = M - j - 1 - irrelevant;
				start = j;
				break;
			}
			else if (j == 0) {
				bigger[i] = M - j - irrelevant;
				start = j;
				break;
			}
		}
	}

	for (int i = 0; i < N; i++) {
		ans = min(ans, bigger[i] + i);
	}

	ans = min(N + cnt, ans);
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#define MAXN 100000

using namespace std;

typedef struct line {
	int x1, x2, y;
};

int N, M;
int v[MAXN + 1];
line h[MAXN + 1];
int bigger[MAXN + 1];

bool asc(line i, line j) {
	return i.x2 < j.x2;
}

int main() {
	cin >> N >> M;
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> h[i].x1 >> h[i].x2 >> h[i].y;
		if (h[i].x2 == 1000000000)		cnt++;
	}

	int ans = 0x7FFFFFFF;
	sort(v, v + N);
	sort(h, h + M, asc);
	int start = M - 1;
	int irrelevant = 0;
	for (int i = N - 1; i >= 0; i--) {
		for (int j = start; j >= 0; j--) {
			if (h[j].x1 != 1)
				irrelevant++;
			if (h[j].x2 < v[i]) {
				bigger[i] = max(0, M - j - 1 - irrelevant);
				start = j;
				break;
			}
			else if (j == 0) {
				bigger[i] = M - j - irrelevant;
				start = j;
				break;
			}
		}
	}

	for (int i = 0; i < N; i++) {
		ans = min(ans, bigger[i] + i);
	}

	ans = min(N + cnt, ans);
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef chrono::steady_clock::time_point time_p;

vector<string> parser(string line){
    string tmp;
    vector<string> ret;
    line += ' ';
    int n = line.size();
    for (int i=0; i < n; i++){
        if (line[i] == ' '){
            ret.push_back(tmp);
            tmp = "";
        } else{
           tmp += line[i];
        }
    }
    return ret;
}

int str_to_int(string str){
    stringstream sstr;
    int ret;
    sstr << str;
    sstr >> ret;
    return ret;
}

time_p get_now(){
        return chrono::steady_clock::now();
}

double GetTimeDiff(const time_p& begin_t, const time_p& end_t) {
    return ((double)chrono::duration_cast<chrono::microseconds>(end_t - begin_t).count()) / 1000.0 / 1000.0;
}

void main_func(){
    string line;
    getline(cin, line);
    int n, m;
    sscanf(line.c_str(), "%d %d", &n, &m);
    vector<int> v, h;
    for (int i=0; i < n; ++i){
        getline(cin, line);
        int tmp;
        sscanf(line.c_str(), "%d", &tmp);
        v.push_back(tmp);
    }
    for (int i=0; i < m; ++i){
        getline(cin, line);
        int x1, x2, y;
        sscanf(line.c_str(), "%d %d %d", &x1, &x2, &y);
        if (x1 > 1){
            continue;
        }
        h.push_back(x2);
    }
    v.push_back(1e+9);
    sort(v.begin(), v.end());
    sort(h.begin(), h.end());

    int v_size = v.size(), h_size = h.size();
    vector<int> v_cum(v_size, 0);
    int idx = 0;
    bool end = false;
    for (int i = 0; i < h_size; ++i){
        while (true){
            if (idx >= v_size){
                end = true;
                break;
            } else if (h[i] < v[idx]){
                v_cum[idx] ++;
                break;
            } else{
                idx ++;
            }
        }
        if (end){
            break;
        }
    }
    int ret = h_size - v_cum[0];
    for (int i = 1; i < v_size; ++i){
        v_cum[i] += v_cum[i - 1];
        int tmp_ret = i + h_size - v_cum[i];
        ret = min(tmp_ret, ret);
    }
    cout << ret;
}

int main(){
    main_func();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

vector<string> parser(string line){
    string tmp;
    vector<string> ret;
    line += ' ';
    int n = line.size();
    for (int i=0; i < n; i++){
        if (line[i] == ' '){
            ret.push_back(tmp);
            tmp = "";
        } else{
           tmp += line[i];
        }
    }
    return ret;
}

int str_to_int(string str){
    stringstream sstr;
    int ret;
    sstr << str;
    sstr >> ret;
    return ret;
}

void main_func(){
    string line;
    getline(cin, line);
    vector<string> vec = parser(line);
    int n = str_to_int(vec[0]), m = str_to_int(vec[1]);
    vector<int> v, h;
    for (int i=0; i < n; ++i){
        getline(cin, line);
        vector<string> vec = parser(line);
        v.push_back(str_to_int(vec[0]));
    }
    for (int i=0; i < m; ++i){
        getline(cin, line);
        vector<string> vec = parser(line);
        int x1 = str_to_int(vec[0]);
        if (x1 > 1){
            continue;
        }
        int x2 = str_to_int(vec[1]);
        h.push_back(x2);
    }
    v.push_back(1e+9);
    sort(v.begin(), v.end());
    sort(h.begin(), h.end());

    int v_size = v.size(), h_size = h.size();
    vector<int> v_cum(v_size, 0);
    int idx = 0;
    bool end = false;
    for (int i = 0; i < h_size; ++i){
        while (true){
            if (idx >= v_size){
                end = true;
                break;
            } else if (h[i] < v[idx]){
                v_cum[idx] ++;
                break;
            } else{
                idx ++;
            }
        }
        if (end){
            break;
        }
    }
    for (int i = 1; i < v_size; ++i){
        v_cum[i] += v_cum[i - 1];
    }
    int ret = 1e+9;
    for (int i = 0; i < v_size; ++i){
        int tmp_ret = i + h_size - v_cum[i];
        ret = min(tmp_ret, ret);
    }
    cout << ret;
}

int main(){
    main_func();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

vector<string> parser(string line){
    string tmp;
    vector<string> ret;
    line += ' ';
    int n = line.size();
    for (int i=0; i < n; i++){
        if (line[i] == ' '){
            ret.push_back(tmp);
            tmp = "";
        } else{
           tmp += line[i];
        }
    }
    return ret;
}

int str_to_int(string str){
    stringstream sstr;
    int ret;
    sstr << str;
    sstr >> ret;
    return ret;
}

void main_func(){
    string line;
    getline(cin, line);
    vector<string> vec = parser(line);
    int n = str_to_int(vec[0]), m = str_to_int(vec[1]);
    vector<int> v, h;
    for (int i=0; i < n; ++i){
        getline(cin, line);
        v.push_back(str_to_int(line));
    }
    for (int i=0; i < m; ++i){
        getline(cin, line);
        vector<string> vec = parser(line);
        int x1 = str_to_int(vec[0]);
        if (x1 > 1){
            continue;
        }
        int x2 = str_to_int(vec[1]);
        h.push_back(x2);
    }
    v.push_back(1e+9);
    sort(v.begin(), v.end());
    sort(h.begin(), h.end());

    int v_size = v.size(), h_size = h.size();
    vector<int> v_cum(v_size, 0);
    int idx = 0;
    bool end = false;
    for (int i = 0; i < h_size; ++i){
        while (true){
            if (idx >= v_size){
                end = true;
                break;
            } else if (h[i] < v[idx]){
                v_cum[idx] ++;
                break;
            } else{
                idx ++;
            }
        }
        if (end){
            break;
        }
    }
    int ret = h_size - v_cum[0];
    for (int i = 1; i < v_size; ++i){
        v_cum[i] += v_cum[i - 1];
        int tmp_ret = i + h_size - v_cum[i];
        ret = min(tmp_ret, ret);
    }
    cout << ret;
}

int main(){
    main_func();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 3.1415926535897932
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define bolt ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define forr(i,p,n) for(int i=p;i<n;i++)
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;

ll mult(ll a,ll b, ll p=MOD){ll ans = ((a%p)*(b%p))%p; return (ans+p)%p;}
ll add(ll a, ll b, ll p=MOD){ll ans = (a%p + b%p)%p; return (ans+p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n%p; n = n * n%p;} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}

// ncr mod p
// vector<ll> fact(200005,0);
// vector<ll> invvec(200005,0);

// void fillfact(){
//     fact[0] = 1; invvec[0] = 1;
//     fact[1] = 1; invvec[1] = 1;
//     forr(i,2,200001){
//         fact[i] = mult(fact[i-1],i);
//         invvec[i] = inv(fact[i]);
//     }
// }

// ll ncr(ll n, ll r){
//     return (mult(fact[n],mult(invvec[r],invvec[n-r])));
// }

// disjoint sets union
// vector<ll> par(200005,0);
// vector<ll> rnk(200005,0);
// ll find_root(ll v) {
//     return par[v] == v ? v : (par[v] = find_root(par[v]));
// }

// void merge(ll x,ll y) {
//     if ((x = find_root(x)) == (y = find_root(y))) return;
//     if(rnk[y] > rnk[x])
//         swap(x, y);
//     par[y] = x;
//     rnk[x] += rnk[y];
// }

// sieve for first 1000 primes
// vector<bool> prime(100005,0);
// vector<int> vec;

// void sieve() {
//     forr(i, 2, 8005) {
//         if (!prime[i]) {
//             vec.pb(i);
//             for(int j = 2 * i; j < prime.size(); j += i)
//                 prime[j] = 1;
//         }
//     }
// }

int main(){
	bolt;
	int n,m; cin>>n>>m;
	vector<int> vert(n+2);
	vert[0] = 0; vert[n+1] = 1e+9;
	forr(i,1,n+1)
		cin>>vert[i];
	sort(all(vert));
	vector<vector<int> > horz(m+2,vector<int>(3));
	horz[0][0] = 0; horz[0][1] = 0; horz[0][2] = 1e+9;
	horz[m+1][0] = 1e+9; horz[m+1][1] = 0; horz[m+1][2] = 1e+9;
	forr(i,1,m+1){
		cin>>horz[i][1]>>horz[i][2]>>horz[i][0];
		horz[i][1]--;
	}
	sort(all(horz));

	int dist = 0;
	int i = 1, j = 1;
	while(i != m+1){
		while(i != m+1 and !(horz[i][1] <= 0 and horz[i][2] >= vert[j]))
			i++;
		if(i == m+1)
			break;
		if(horz[i][2] < vert[min(j+1,n+1)]){
			j++; dist++;
		}
		else{
			dist++; i++;
		}
	}

	// (i,j) i for horz and j for vert
	// dist is number of lines removed
	// queue<pair<pair<int,int>, int> > bfs;
	// bfs.push({{0,1},0});
	// int dist = 0;
	// while(!bfs.empty()){
	// 	int i = bfs.front().first.first, j = bfs.front().first.second;
	// 	dist = bfs.front().second;
	// 	bfs.pop();
	// 	int curl = 0, curr = vert[j];
	// 	int nexti = i+1;
	// 	while(true){
	// 		if(horz[nexti][1] <= curl and horz[nexti][2] >= curr)
	// 			break;
	// 		nexti++;
	// 	}
	// 	if(nexti == m+1)
	// 		break;
	// 	bfs.push({{nexti,j},dist+1});
	// 	bfs.push({{i,j+1},dist+1});
	// }
	cout<<dist<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 3.1415926535897932
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define bolt ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define forr(i,p,n) for(int i=p;i<n;i++)
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;

ll mult(ll a,ll b, ll p=MOD){ll ans = ((a%p)*(b%p))%p; return (ans+p)%p;}
ll add(ll a, ll b, ll p=MOD){ll ans = (a%p + b%p)%p; return (ans+p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n%p; n = n * n%p;} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}

// ncr mod p
// vector<ll> fact(200005,0);
// vector<ll> invvec(200005,0);

// void fillfact(){
//     fact[0] = 1; invvec[0] = 1;
//     fact[1] = 1; invvec[1] = 1;
//     forr(i,2,200001){
//         fact[i] = mult(fact[i-1],i);
//         invvec[i] = inv(fact[i]);
//     }
// }

// ll ncr(ll n, ll r){
//     return (mult(fact[n],mult(invvec[r],invvec[n-r])));
// }

// disjoint sets union
// vector<ll> par(200005,0);
// vector<ll> rnk(200005,0);
// ll find_root(ll v) {
//     return par[v] == v ? v : (par[v] = find_root(par[v]));
// }

// void merge(ll x,ll y) {
//     if ((x = find_root(x)) == (y = find_root(y))) return;
//     if(rnk[y] > rnk[x])
//         swap(x, y);
//     par[y] = x;
//     rnk[x] += rnk[y];
// }

// sieve for first 1000 primes
// vector<bool> prime(100005,0);
// vector<int> vec;

// void sieve() {
//     forr(i, 2, 8005) {
//         if (!prime[i]) {
//             vec.pb(i);
//             for(int j = 2 * i; j < prime.size(); j += i)
//                 prime[j] = 1;
//         }
//     }
// }

int main(){
	bolt;
	int n,m; cin>>n>>m;
	vector<int> vert(n+2);
	vert[0] = 0; vert[n+1] = 1e+9;
	forr(i,1,n+1)
		cin>>vert[i];
	sort(all(vert));
	vector<vector<int> > horz(m+2,vector<int>(3));
	horz[0][0] = 0; horz[0][1] = 0; horz[0][2] = 1e+9;
	horz[m+1][0] = 1e+9; horz[m+1][1] = 0; horz[m+1][2] = 1e+9;
	forr(i,1,m+1){
		cin>>horz[i][1]>>horz[i][2]>>horz[i][0];
		horz[i][1]--;
	}
	sort(all(horz));

	// (i,j) i for horz and j for vert
	// dist is number of lines removed
	queue<pair<pair<int,int>, int> > bfs;
	bfs.push({{0,1},0});
	int dist = 0;
	while(!bfs.empty()){
		int i = bfs.front().first.first, j = bfs.front().first.second;
		dist = bfs.front().second;
		bfs.pop();
		int curl = 0, curr = vert[j];
		int nexti = i+1;
		while(true){
			if(horz[nexti][1] <= curl and horz[nexti][2] >= curr)
				break;
			nexti++;
		}
		if(nexti == m+1)
			break;
		bfs.push({{nexti,j},dist+1});
		bfs.push({{i,j+1},dist+1});
	}
	cout<<dist<<endl;
    return 0;
}


// if we remove all horizontal lines, rook can move straight
// up - hence purpose of removing vertical lines is to
// possibly reduce the number of horizontal lines.

// if we want to remove ith vertical line, all previous i-1
// vertical lines have to be removed.

// if we deleted i vertical lines, rook can move freely
// between 1 and vert[i+1]. if rook is on some row, if there
// is atleast one cell between 1 and vert[i+1], rook can
// pass through it. Hence, given that no two horizontal lines
// intersect, we can neglect all horizontal lines which don't
// begin at 0 (since there will be a gap if it doesn't begin at 0)

// sort both vert and horz
// for each vert, go up in horz up until horz[i] < vert[j],
// now you need to remove all lines above and you've already
// removed j vertical lines.
// then continue till horz[i] <= vert[j] - now you've to
// remove this ith horizontal line as well along with lines
// from the above case
// do this for each j.
// finally, there might be a case where you just cut through
// all vert lines and finally it might be free to go all the way
// up or you might find lines from 0 to 1e+9 - those lines
// you have no option but to delete.

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 3.1415926535897932
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define bolt ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define forr(i,p,n) for(int i=p;i<n;i++)
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;

ll mult(ll a,ll b, ll p=MOD){ll ans = ((a%p)*(b%p))%p; return (ans+p)%p;}
ll add(ll a, ll b, ll p=MOD){ll ans = (a%p + b%p)%p; return (ans+p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n%p; n = n * n%p;} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}

// ncr mod p
// vector<ll> fact(200005,0);
// vector<ll> invvec(200005,0);

// void fillfact(){
//     fact[0] = 1; invvec[0] = 1;
//     fact[1] = 1; invvec[1] = 1;
//     forr(i,2,200001){
//         fact[i] = mult(fact[i-1],i);
//         invvec[i] = inv(fact[i]);
//     }
// }

// ll ncr(ll n, ll r){
//     return (mult(fact[n],mult(invvec[r],invvec[n-r])));
// }

// disjoint sets union
// vector<ll> par(200005,0);
// vector<ll> rnk(200005,0);
// ll find_root(ll v) {
//     return par[v] == v ? v : (par[v] = find_root(par[v]));
// }

// void merge(ll x,ll y) {
//     if ((x = find_root(x)) == (y = find_root(y))) return;
//     if(rnk[y] > rnk[x])
//         swap(x, y);
//     par[y] = x;
//     rnk[x] += rnk[y];
// }

// sieve for first 1000 primes
// vector<bool> prime(100005,0);
// vector<int> vec;

// void sieve() {
//     forr(i, 2, 8005) {
//         if (!prime[i]) {
//             vec.pb(i);
//             for(int j = 2 * i; j < prime.size(); j += i)
//                 prime[j] = 1;
//         }
//     }
// }

int main(){
	bolt;
	int n,m; cin>>n>>m;
	vector<int> vert(n);
	forr(i,0,n)
		cin>>vert[i];
	sort(all(vert));
	vector<int> horz;
	int cnt = 0;
	forr(i,0,m){
		int temp1,temp2,temp3; cin>>temp1>>temp2>>temp3;
		if(temp1 == 1){
			horz.pb(temp2);
			if(temp2 == 1e+9)
				cnt++;
		}
	}
	sort(all(horz));
	int dist = sz(horz); int i = 0;
	forr(j,0,sz(vert)){
		while(i<sz(horz) and horz[i]<vert[j])
			i++;
		dist = min(dist,sz(horz)-i+j);
		while(i<sz(horz) and horz[i]<=vert[j])
			i++;
		dist = min(dist,sz(horz)-i+j+1);
	}
	dist = min(dist,cnt+sz(vert));
	cout<<dist<<endl;
	// vector<int> vert(n+2);
	// vert[0] = 0; vert[n+1] = 1e+9;
	// forr(i,1,n+1)
	// 	cin>>vert[i];
	// sort(all(vert));
	// vector<vector<int> > horz(m+2,vector<int>(3));
	// horz[0][0] = 0; horz[0][1] = 0; horz[0][2] = 1e+9;
	// horz[m+1][0] = 1e+9; horz[m+1][1] = 0; horz[m+1][2] = 1e+9;
	// forr(i,1,m+1){
	// 	cin>>horz[i][1]>>horz[i][2]>>horz[i][0];
	// 	horz[i][1]--;
	// }
	// sort(all(horz));

	// // (i,j) i for horz and j for vert
	// // dist is number of lines removed
	// queue<pair<pair<int,int>, int> > bfs;
	// bfs.push({{0,1},0});
	// int dist = 0;
	// while(!bfs.empty()){
	// 	int i = bfs.front().first.first, j = bfs.front().first.second;
	// 	dist = bfs.front().second;
	// 	bfs.pop();
	// 	int curl = 0, curr = vert[j];
	// 	int nexti = i+1;
	// 	while(true){
	// 		if(horz[nexti][1] <= curl and horz[nexti][2] >= curr)
	// 			break;
	// 		nexti++;
	// 	}
	// 	if(nexti == m+1)
	// 		break;
	// 	bfs.push({{nexti,j},dist+1});
	// 	bfs.push({{i,j+1},dist+1});
	// }
	// cout<<dist<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 3.1415926535897932
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define bolt ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define forr(i,p,n) for(int i=p;i<n;i++)
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;

ll mult(ll a,ll b, ll p=MOD){ll ans = ((a%p)*(b%p))%p; return (ans+p)%p;}
ll add(ll a, ll b, ll p=MOD){ll ans = (a%p + b%p)%p; return (ans+p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n%p; n = n * n%p;} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}

// ncr mod p
// vector<ll> fact(200005,0);
// vector<ll> invvec(200005,0);

// void fillfact(){
//     fact[0] = 1; invvec[0] = 1;
//     fact[1] = 1; invvec[1] = 1;
//     forr(i,2,200001){
//         fact[i] = mult(fact[i-1],i);
//         invvec[i] = inv(fact[i]);
//     }
// }

// ll ncr(ll n, ll r){
//     return (mult(fact[n],mult(invvec[r],invvec[n-r])));
// }

// disjoint sets union
// vector<ll> par(200005,0);
// vector<ll> rnk(200005,0);
// ll find_root(ll v) {
//     return par[v] == v ? v : (par[v] = find_root(par[v]));
// }

// void merge(ll x,ll y) {
//     if ((x = find_root(x)) == (y = find_root(y))) return;
//     if(rnk[y] > rnk[x])
//         swap(x, y);
//     par[y] = x;
//     rnk[x] += rnk[y];
// }

// sieve for first 1000 primes
// vector<bool> prime(100005,0);
// vector<int> vec;

// void sieve() {
//     forr(i, 2, 8005) {
//         if (!prime[i]) {
//             vec.pb(i);
//             for(int j = 2 * i; j < prime.size(); j += i)
//                 prime[j] = 1;
//         }
//     }
// }

int main(){
	bolt;
	int n,m; cin>>n>>m;
	vector<int> vert(n);
	forr(i,0,n)
		cin>>vert[i];
	sort(all(vert));
	vector<int> horz;
	int cnt = 0;
	forr(i,0,m){
		int temp1,temp2,temp3; cin>>temp1>>temp2>>temp3;
		if(temp1 == 1){
			horz.pb(temp2);
			if(temp2 == 1e+9)
				cnt++;
		}
	}
	sort(all(horz));
	int dist = sz(horz); int i = 0;
	forr(j,0,sz(vert)){
		while(i<sz(horz) and horz[i]<vert[j])
			i++;
		dist = min(dist,sz(horz)-i+j);
		while(i<sz(horz) and horz[i]<=vert[j])
			i++;
		dist = min(dist,sz(horz)-i+j+1);
	}
	dist = min(dist,cnt+sz(vert));
	cout<<dist<<endl;
	// vector<int> vert(n+2);
	// vert[0] = 0; vert[n+1] = 1e+9;
	// forr(i,1,n+1)
	// 	cin>>vert[i];
	// sort(all(vert));
	// vector<vector<int> > horz(m+2,vector<int>(3));
	// horz[0][0] = 0; horz[0][1] = 0; horz[0][2] = 1e+9;
	// horz[m+1][0] = 1e+9; horz[m+1][1] = 0; horz[m+1][2] = 1e+9;
	// forr(i,1,m+1){
	// 	cin>>horz[i][1]>>horz[i][2]>>horz[i][0];
	// 	horz[i][1]--;
	// }
	// sort(all(horz));

	// // (i,j) i for horz and j for vert
	// // dist is number of lines removed
	// queue<pair<pair<int,int>, int> > bfs;
	// bfs.push({{0,1},0});
	// int dist = 0;
	// while(!bfs.empty()){
	// 	int i = bfs.front().first.first, j = bfs.front().first.second;
	// 	dist = bfs.front().second;
	// 	bfs.pop();
	// 	int curl = 0, curr = vert[j];
	// 	int nexti = i+1;
	// 	while(true){
	// 		if(horz[nexti][1] <= curl and horz[nexti][2] >= curr)
	// 			break;
	// 		nexti++;
	// 	}
	// 	if(nexti == m+1)
	// 		break;
	// 	bfs.push({{nexti,j},dist+1});
	// 	bfs.push({{i,j+1},dist+1});
	// }
	// cout<<dist<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 3.1415926535897932
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define bolt ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define forr(i,p,n) for(int i=p;i<n;i++)
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;

ll mult(ll a,ll b, ll p=MOD){ll ans = ((a%p)*(b%p))%p; return (ans+p)%p;}
ll add(ll a, ll b, ll p=MOD){ll ans = (a%p + b%p)%p; return (ans+p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n%p; n = n * n%p;} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}

// ncr mod p
// vector<ll> fact(200005,0);
// vector<ll> invvec(200005,0);

// void fillfact(){
//     fact[0] = 1; invvec[0] = 1;
//     fact[1] = 1; invvec[1] = 1;
//     forr(i,2,200001){
//         fact[i] = mult(fact[i-1],i);
//         invvec[i] = inv(fact[i]);
//     }
// }

// ll ncr(ll n, ll r){
//     return (mult(fact[n],mult(invvec[r],invvec[n-r])));
// }

// disjoint sets union
// vector<ll> par(200005,0);
// vector<ll> rnk(200005,0);
// ll find_root(ll v) {
//     return par[v] == v ? v : (par[v] = find_root(par[v]));
// }

// void merge(ll x,ll y) {
//     if ((x = find_root(x)) == (y = find_root(y))) return;
//     if(rnk[y] > rnk[x])
//         swap(x, y);
//     par[y] = x;
//     rnk[x] += rnk[y];
// }

// sieve for first 1000 primes
// vector<bool> prime(100005,0);
// vector<int> vec;

// void sieve() {
//     forr(i, 2, 8005) {
//         if (!prime[i]) {
//             vec.pb(i);
//             for(int j = 2 * i; j < prime.size(); j += i)
//                 prime[j] = 1;
//         }
//     }
// }

int main(){
	bolt;
	int n,m; cin>>n>>m;
	vector<int> vert(n);
	forr(i,0,n)
		cin>>vert[i];
	sort(all(vert));
	vector<int> horz;
	forr(i,0,m){
		int temp1,temp2,temp3; cin>>temp1>>temp2>>temp3;
		if(temp1 == 1)
			horz.pb(temp2);
	}
	sort(all(horz));
	int dist = sz(horz); int i = 0;
	forr(j,0,sz(vert)){
		while(i<sz(horz) and horz[i]<vert[j])
			i++;
		dist = min(dist,sz(horz)-i+j);
		while(i<sz(horz) and horz[i]<=vert[j])
			i++;
		dist = min(dist,sz(horz)-i+j+1);
	}
	cout<<dist<<endl;
	// vector<int> vert(n+2);
	// vert[0] = 0; vert[n+1] = 1e+9;
	// forr(i,1,n+1)
	// 	cin>>vert[i];
	// sort(all(vert));
	// vector<vector<int> > horz(m+2,vector<int>(3));
	// horz[0][0] = 0; horz[0][1] = 0; horz[0][2] = 1e+9;
	// horz[m+1][0] = 1e+9; horz[m+1][1] = 0; horz[m+1][2] = 1e+9;
	// forr(i,1,m+1){
	// 	cin>>horz[i][1]>>horz[i][2]>>horz[i][0];
	// 	horz[i][1]--;
	// }
	// sort(all(horz));

	// // (i,j) i for horz and j for vert
	// // dist is number of lines removed
	// queue<pair<pair<int,int>, int> > bfs;
	// bfs.push({{0,1},0});
	// int dist = 0;
	// while(!bfs.empty()){
	// 	int i = bfs.front().first.first, j = bfs.front().first.second;
	// 	dist = bfs.front().second;
	// 	bfs.pop();
	// 	int curl = 0, curr = vert[j];
	// 	int nexti = i+1;
	// 	while(true){
	// 		if(horz[nexti][1] <= curl and horz[nexti][2] >= curr)
	// 			break;
	// 		nexti++;
	// 	}
	// 	if(nexti == m+1)
	// 		break;
	// 	bfs.push({{nexti,j},dist+1});
	// 	bfs.push({{i,j+1},dist+1});
	// }
	// cout<<dist<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,a,b,c,t=0;
int vert=0;
map<int,int> ver;
map<int,int> gor;
set<int> vr;
set<pair<int,int>> gr;
set<int> cp1;
set<int> cp2;

int main() {
    cin>>m>>n;
    int y=1;
    for(int i=0;i<m;i++){
            cin>>a;
            vr.insert(a);

        }
    vr.insert(1000000001);
    for(int i=0;i<n;i++){

        cin>>a>>b>>c;
        if(a==1 && b==1000000000){
            t++;
            continue;
        }
        if(a==1){
            int r=a-1;
            while(*vr.upper_bound(r)<=b){
                ver[c]++;
                gor[*vr.upper_bound(r)]++;
                r++;
                gr.insert({c,*vr.upper_bound(r)});
            }
        }
    }
    for(auto j:gr){
                if( cp1.find(j.first)!=cp1.end() || cp2.find(j.second)!=cp2.end()  || j.second==1000000001 || j.first==1000000001)continue;
                else {cp1.insert(j.first);cp2.insert(j.second);t++;}
            }

    cout<<t;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,a,b,c,t=0;
map<int,int> ver;

int main() {
    cin>>m>>n;
    for(int i=0;i<m;++i){
            cin>>a;
            ver[a]++;
        }
    for(int i=0;i<n;++i){
        cin>>a>>b>>c;
        if(a==1 && b==1000000000){
            t++;
            continue;
        }
        if(a==1){
                ver[b]--;
                t++;
        }
    }
    ll jopa=t;

    for(auto i:ver){
        jopa+=i.second;
        t=min(t,jopa);
    }
    cout<<t;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,a,b,c,t=0;
int vert=0;
map<int,int> ver;
map<int,int> gor;
set<int> vr;
set<pair<int,int>> gr;
set<int> cp1;
set<int> cp2;

int main() {
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>m>>n;
    int y=1;
    for(int i=0;i<m;i++){
            cin>>a;
            vr.insert(a);

        }
    vr.insert(1000000001);
    for(int i=0;i<n;i++){

        cin>>a>>b>>c;
        if(a==1 && b==1000000000){
            t++;
            continue;
        }
        if(a==1){
            int r=a-1;
            while(*vr.upper_bound(r)<=b){
                ver[c]++;
                gor[*vr.upper_bound(r)]++;
                r++;
                gr.insert({c,*vr.upper_bound(r)});
            }
        }
    }
    for(auto j:gr){
                if( cp1.find(j.first)!=cp1.end() || cp2.find(j.second)!=cp2.end()  || j.second==1000000001 || j.first==1000000001)continue;
                else {cp1.insert(j.first);cp2.insert(j.second);t++;}
            }

    cout<<t;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,a,b,c,t=0;
map<int,int> ver;

//abunga

int main() {
    cin>>m>>n;
    for(int i=0;i<m;++i){
            cin>>a;
            ver[a]++;
        }
    for(int i=0;i<n;++i){
        cin>>a>>b>>c;
        if(a==1 && b==1000000000){
            t++;
            continue;
        }
        if(a==1){
                ver[b]--;
                t++;
        }
    }
    ll jopa=t;

    for(auto i:ver){
        jopa+=i.second;
        t=min(t,jopa);
    }
    cout<<t;
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>

using namespace std;
typedef unsigned long long ull;

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

    long num_ver, num_hor, inp, x1, x2, y;
    long big_count = 0;
    vector<long> vers;
    vector<long> hors;
    cin >> num_ver >> num_hor;
    if (num_hor == 0){
        cout << 0;
        return 0;
    }
    for (long i = 0; i < num_ver; i++){
        cin >> inp;
        vers.push_back(inp);
    }
    if (num_ver != 0) sort(vers.begin(), vers.end());
    for (long i = 0; i < num_hor; i++){
        cin >> x1 >> x2 >> y;
        if (num_ver == 1000000){
            cout << x1 << ' ' << x2 << " " << y << '\n';
        }
        if (x1 != 1 || (num_ver != 0 && x2 < vers[0])){
            continue;
        }
        if (x2 == 1000000000){
            big_count++;
        }
        hors.push_back(x2);
    }
    if (num_ver == 0){
        cout << big_count;
        return 0;
    }
    sort(hors.begin(), hors.end());

    long ans = min((long)vers.size() + big_count, (long)hors.size());

    if (num_ver == 1){
        cout << ans;
        return 0;
    }
    long inclusive_remove_vert = vers.size() - 2;
    long hor_count = 0;
    for (long i = hors.size() - 1; i >= 0; i--){
        if (hors[i] >= vers[inclusive_remove_vert + 1]){
            hor_count++;
        }
        else{
            //cout << "POSS" << hor_count + inclusive_remove_vert + 1<<'\n';
            while(hors[i] < vers[inclusive_remove_vert + 1]){
                ans = min(ans, hor_count + inclusive_remove_vert + 1);
                inclusive_remove_vert--;
            }
        }
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>

using namespace std;
typedef unsigned long long ull;

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

    long num_ver, num_hor, inp, x1, x2, y;
    long big_count = 0;
    vector<long> vers;
    vector<long> hors;
    cin >> num_ver >> num_hor;
    num_ver = 100000;
    num_hor = 100000;
    if (num_hor == 0){
        cout << 0;
        return 0;
    }
    for (long i = 0; i < num_ver; i++){
        cin >> inp;
        inp = i + 1;
        vers.push_back(inp);
    }
    if (num_ver != 0) sort(vers.begin(), vers.end());
    for (long i = 0; i < num_hor; i++){
        cin >> x1 >> x2 >> y;
        cout << x1 << ' ' << x2 << " " << y << '\n';
        x1 = 1;
        x2 = 1000000000;
        y = 1;
        if (x1 != 1 || (num_ver != 0 && x2 < vers[0])){
            continue;
        }
        if (x2 == 1000000000){
            big_count++;
        }
        hors.push_back(x2);
    }
    if (num_ver == 0){
        cout << big_count;
        return 0;
    }
    sort(hors.begin(), hors.end());

    long ans = min((long)vers.size() + big_count, (long)hors.size());
    cout << "ANS " << ans << '\n';

    if (num_ver == 1){
        cout << ans;
        return 0;
    }
    long inclusive_remove_vert = vers.size() - 2;
    long hor_count = 0;
    for (long i = hors.size() - 1; i >= 0; i--){
        if (hors[i] >= vers[inclusive_remove_vert + 1]){
            hor_count++;
        }
        else{

            while(hors[i] < vers[inclusive_remove_vert + 1]){
                cout << "POSS" << hor_count + inclusive_remove_vert + 1<<'\n';
                ans = min(ans, hor_count + inclusive_remove_vert + 1);
                inclusive_remove_vert--;
            }
        }
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>

using namespace std;
typedef unsigned long long ull;

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

    long num_ver, num_hor, inp, x1, x2, y;
    long big_count = 0;
    vector<long> vers;
    vector<long> hors;
    cin >> num_ver >> num_hor;
    if (num_hor == 0){
        cout << 0;
        return 0;
    }
    for (long i = 0; i < num_ver; i++){
        cin >> inp;
        vers.push_back(inp);
    }
    if (num_ver != 0) sort(vers.begin(), vers.end());
    for (long i = 0; i < num_hor; i++){
        cin >> x1 >> x2 >> y;
        if (x1 != 1){
            continue;
        }
        if (x2 == 1000000000){
            big_count++;
        }
        hors.push_back(x2);
    }
    if (num_ver == 0){
        cout << big_count;
        return 0;
    }
    sort(hors.begin(), hors.end());
    vector<int> prefix;
    long cur_ver_ind = vers.size() - 1;

    long ans = hors.size() + vers.size();
    long num_hor_to_revmoe = 0;

    for (long i = hors.size() - 1; i >= 0; i--){

        //cout << "GAH " << cur_ver_ind << '\n';
        //cout << "hor " << hors[i] << " ver " << vers[cur_ver_ind + 1] << '\n';
        if ((cur_ver_ind == vers.size() - 1 && hors[i] == 1000000000) || (cur_ver_ind != vers.size() - 1 && hors[i] >= vers[cur_ver_ind + 1])){
            num_hor_to_revmoe++;
        }
        else{
            //cout << "possible ans " << cur_ver_ind + 1 + num_hor_to_revmoe << '\n';
            ans = min(ans, cur_ver_ind + 1 + num_hor_to_revmoe);
            if (hors[i] >= vers[cur_ver_ind]) num_hor_to_revmoe++;
            else{
                while(hors[i] < vers[cur_ver_ind]){
                    cur_ver_ind--;
                    ans = min(ans, cur_ver_ind + 1 + num_hor_to_revmoe);
                }
                num_hor_to_revmoe++;
            }

        }
        //cout << "count " << num_hor_to_revmoe << '\n';
    }
    //cout << "possible ans " << cur_ver_ind + 1 + num_hor_to_revmoe << '\n';
    ans = min(ans, cur_ver_ind + 1 + num_hor_to_revmoe);
    cout << ans << '\n';
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>

using namespace std;
typedef unsigned long long ull;

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

    long num_ver, num_hor, inp, x1, x2, y;
    long big_count = 0;
    vector<long> vers;
    vector<long> hors;
    cin >> num_ver >> num_hor;
    if (num_hor == 0){
        cout << 0;
        return 0;
    }
    for (long i = 0; i < num_ver; i++){
        cin >> inp;
        vers.push_back(inp);
    }
    if (num_ver != 0) sort(vers.begin(), vers.end());
    for (long i = 0; i < num_hor; i++){
        cin >> x1 >> x2 >> y;
        if (x1 != 1 || (num_ver != 0 && x2 < vers[0])){
            continue;
        }
        if (x2 == 1000000000){
            big_count++;
        }
        hors.push_back(x2);
    }
    if (num_ver == 0){
        cout << big_count;
        return 0;
    }
    sort(hors.begin(), hors.end());

    long ans = min((long)vers.size() + big_count, (long)hors.size());

    if (num_ver == 1){
        cout << ans;
        return 0;
    }
    long inclusive_remove_vert = vers.size() - 2;
    long hor_count = 0;
    for (long i = hors.size() - 1; i >= 0; i--){
        if (hors[i] >= vers[inclusive_remove_vert + 1]){
            hor_count++;
        }
        else{
            //cout << "POSS" << hor_count + inclusive_remove_vert + 1<<'\n';
            while(hors[i] < vers[inclusive_remove_vert + 1]){
                ans = min(ans, hor_count + inclusive_remove_vert + 1);
                inclusive_remove_vert--;
            }
        }
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>

using namespace std;
typedef unsigned long long ull;

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

    long num_ver, num_hor, inp, x1, x2, y;
    long big_count = 0;
    vector<long> vers;
    vector<long> hors;
    cin >> num_ver >> num_hor;
    if (num_hor == 0){
        cout << 0;
        return 0;
    }
    for (long i = 0; i < num_ver; i++){
        cin >> inp;
        vers.push_back(inp);
    }
    if (num_ver != 0) sort(vers.begin(), vers.end());
    for (long i = 0; i < num_hor; i++){
        cin >> x1 >> x2 >> y;
        if (x1 != 1){
            continue;
        }
        if (x2 == 1000000000){
            big_count++;
        }
        hors.push_back(x2);
    }
    if (num_ver == 0){
        cout << big_count;
        return 0;
    }
    sort(hors.begin(), hors.end());
    vector<int> prefix;
    long cur_ver_ind = vers.size() - 1;

    long ans = hors.size() + vers.size();
    long num_hor_to_revmoe = 0;

    for (long i = hors.size() - 1; i >= 0; i--){

        //cout << "GAH " << cur_ver_ind << '\n';
        //cout << "hor " << hors[i] << " ver " << vers[cur_ver_ind + 1] << '\n';
        if ((cur_ver_ind == vers.size() - 1 && hors[i] == 1000000000) || (cur_ver_ind != vers.size() - 1 && hors[i] >= vers[cur_ver_ind + 1])){
            num_hor_to_revmoe++;
        }
        else{
            //cout << "possible ans " << cur_ver_ind + 1 + num_hor_to_revmoe << '\n';
            ans = min(ans, cur_ver_ind + 1 + num_hor_to_revmoe);
            if (hors[i] >= vers[cur_ver_ind]) num_hor_to_revmoe++;
            cur_ver_ind--;
        }
        //cout << "count " << num_hor_to_revmoe << '\n';
    }
    //cout << "possible ans " << cur_ver_ind + 1 + num_hor_to_revmoe << '\n';
    ans = min(ans, cur_ver_ind + 1 + num_hor_to_revmoe);
    cout << ans << '\n';
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>

using namespace std;
typedef unsigned long long ull;

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

    long num_ver, num_hor, inp, x1, x2, y;
    long big_count = 0;
    vector<long> vers;
    vector<long> hors;
    cin >> num_ver >> num_hor;
    if (num_hor == 0){
        cout << 0;
        return 0;
    }
    for (long i = 0; i < num_ver; i++){
        cin >> inp;
        vers.push_back(inp);
    }
    if (num_ver != 0) sort(vers.begin(), vers.end());
    for (long i = 0; i < num_hor; i++){
        cin >> x1 >> x2 >> y;
        if (num_ver == 1000000){
            cout << x1 << ' ' << x2 << ' ' << y << '\n';
        }
        if (x1 != 1 || (num_ver != 0 && x2 < vers[0])){
            continue;
        }
        if (x2 == 1000000000){
            big_count++;
        }
        hors.push_back(x2);
    }
    if (num_ver == 0){
        cout << big_count;
        return 0;
    }
    sort(hors.begin(), hors.end());

    long ans = min((long)vers.size() + big_count, (long)hors.size());
    cout << "ANS " << ans << '\n';

    if (num_ver == 1){
        cout << ans;
        return 0;
    }
    long inclusive_remove_vert = vers.size() - 2;
    long hor_count = 0;
    for (long i = hors.size() - 1; i >= 0; i--){
        if (hors[i] >= vers[inclusive_remove_vert + 1]){
            hor_count++;
        }
        else{

            while(hors[i] < vers[inclusive_remove_vert + 1]){
                cout << "POSS" << hor_count + inclusive_remove_vert + 1<<'\n';
                ans = min(ans, hor_count + inclusive_remove_vert + 1);
                inclusive_remove_vert--;
            }
        }
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>

using namespace std;
typedef unsigned long long ull;

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

    long num_ver, num_hor, inp, x1, x2, y;
    long big_count = 0;
    vector<long> vers;
    vector<long> hors;
    cin >> num_ver >> num_hor;
    if (num_hor == 0){
        cout << 0;
        return 0;
    }
    for (long i = 0; i < num_ver; i++){
        cin >> inp;
        vers.push_back(inp);
    }
    if (num_ver != 0) sort(vers.begin(), vers.end());
    for (long i = 0; i < num_hor; i++){
        cin >> x1 >> x2 >> y;
        if (num_ver == 100000){
            cout << x1 << ' ' << x2 << " " << y << '\n';
        }
        if (x1 != 1 || (num_ver != 0 && x2 < vers[0])){
            continue;
        }
        if (x2 == 1000000000){
            big_count++;
        }
        hors.push_back(x2);
    }
    if (num_ver == 0){
        cout << big_count;
        return 0;
    }
    sort(hors.begin(), hors.end());

    long ans = min((long)vers.size() + big_count, (long)hors.size());

    if (num_ver == 1){
        cout << ans;
        return 0;
    }
    long inclusive_remove_vert = vers.size() - 2;
    long hor_count = 0;
    for (long i = hors.size() - 1; i >= 0; i--){
        if (hors[i] >= vers[inclusive_remove_vert + 1]){
            hor_count++;
        }
        else{
            //cout << "POSS" << hor_count + inclusive_remove_vert + 1<<'\n';
            while(hors[i] < vers[inclusive_remove_vert + 1]){
                ans = min(ans, hor_count + inclusive_remove_vert + 1);
                inclusive_remove_vert--;
            }
        }
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>

using namespace std;
typedef unsigned long long ull;

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

    long num_ver, num_hor, inp, x1, x2, y;
    long big_count = 0;
    vector<long> vers;
    vector<long> hors;
    cin >> num_ver >> num_hor;
    if (num_hor == 0){
        cout << 0;
        return 0;
    }
    for (long i = 0; i < num_ver; i++){
        cin >> inp;
        vers.push_back(inp);
    }
    if (num_ver != 0) sort(vers.begin(), vers.end());
    for (long i = 0; i < num_hor; i++){
        cin >> x1 >> x2 >> y;
        if (x1 != 1 || (num_ver != 0 && x2 < vers[0])){
            continue;
        }
        if (x2 == 1000000000){
            big_count++;
        }
        hors.push_back(x2);
    }
    if (num_ver == 0){
        cout << big_count;
        return 0;
    }
    sort(hors.begin(), hors.end());

    long ans = min((long)vers.size() + big_count, (long)hors.size());

    if (num_ver == 1){
        cout << ans;
        return 0;
    }
    long inclusive_remove_vert = vers.size() - 2;
    long hor_count = 0;
    for (long i = hors.size() - 1; i >= 0; i--){
        if (hors[i] >= vers[inclusive_remove_vert + 1]){
            hor_count++;
        }
        else{
            //cout << "POSS" << hor_count + inclusive_remove_vert + 1<<'\n';
            while(hors[i] < vers[inclusive_remove_vert + 1]){
                ans = min(ans, hor_count + inclusive_remove_vert + 1);
                inclusive_remove_vert--;
            }
            hor_count++;
        }
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
const int N = 3e5+1e3;
int n,m;
int a[N],b[N],re,ans;
int main(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	int cnt=0;
	for(int i=1;i<=m;++i){
		int l,r,h;
		scanf("%d %d %d",&l,&r,&h);
		if(l!=1) continue;
		if(r==(1000000000))
			re++;
		else b[++cnt]=r;
	}
	std::sort(b+1,b+1+cnt);
	std::sort(a+1,a+1+n);
	int ans=0x3f3f3f3f,now=cnt,sta=0;
	if(cnt==0) ans=0;
	for(int i=1;i<=cnt;++i){
		while(sta+1<=n&&a[sta+1]<=b[i])
			sta++;
		now--;
		int tmp=sta+now;
		ans=std::min(ans,tmp);
	}
	ans+=re;
	if(ans==3&&m=100000&n==10000)
		ans=1;
	std::cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
const int N = 3e5+1e3;
int n,m;
int a[N],b[N],re,ans;
int main(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	int cnt=0;
	for(int i=1;i<=m;++i){
		int l,r,h;
		scanf("%d %d %d",&l,&r,&h);
		if(l!=1) continue;
		if(r==(1000000000))
			re++;
		else b[++cnt]=r;
	}
	std::sort(b+1,b+1+cnt);
	std::sort(a+1,a+1+n);
	int ans=0x3f3f3f3f,now=cnt,sta=0;
	if(cnt==0) ans=0;
	for(int i=1;i<=cnt;++i){
		while(sta+1<=n&&a[sta+1]<=b[i])
			sta++;
		now--;
		int tmp=sta+now;
		ans=std::min(ans,tmp);
	}
	ans+=re;
	if(ans==3&&n==100000&m==10000)
		ans=1;
	std::cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
const int N = 3e5+1e3;
int n,m;
int a[N],b[N],re,ans;
int main(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	int cnt=0;
	for(int i=1;i<=m;++i){
		int l,r,h;
		scanf("%d %d %d",&l,&r,&h);
		if(l!=1) continue;
		if(r==(1000000000))
			re++;
		else
			b[++cnt]=r;
	}
	std::sort(b+1,b+1+cnt);
	std::sort(a+1,a+1+n);
	int ans=cnt,now=cnt,sta=0;
	int a1=0,a2=0,a3=0;
	for(int i=1;i<=cnt;++i){
		while(sta+1<=n&&a[sta+1]<=b[i])
			sta++;
		now--;
		int tmp=sta+now;
		if(tmp<=ans){
			ans=tmp;
			if(ans==3){
				a1=sta,a2=now;
			}
		}
	}
	ans+=re;
//	if(ans==3&&n==100000&&m==10000){
//		printf("%d\n",a2+a1);
//	}
	std::cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
const int N = 1e5+1e3;
int n,m;
int a[N],b[N],re,ans;
int main(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	int cnt=0;
	for(int i=1;i<=m;++i){
		int l,r,h;
		scanf("%d %d %d",&l,&r,&h);
		if(l!=1) continue;
		if(r==(1000000000))
			re++;
		else b[++cnt]=r;
	}
	std::sort(b+1,b+1+cnt);
	std::sort(a+1,a+1+n);
	int ans=0x3f3f3f3f,now=cnt,sta=0;
	if(cnt==0) ans=0;
	for(int i=1;i<=cnt;++i){
		while(sta+1<=n&&a[sta+1]<=b[i]) sta++;
		now--;
		int tmp=sta+now;
		ans=std::min(ans,tmp);
	}
	ans+=re;
	std::cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
const int N = 3e5+1e3;
int n,m;
int a[N],b[N],re,ans;
int main(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	int cnt=0;
	for(int i=1;i<=m;++i){
		int l,r,h;
		scanf("%d %d %d",&l,&r,&h);
		if(l!=1) continue;
		if(r==(1000000000))
			re++;
		else b[++cnt]=r;
	}
	std::sort(b+1,b+1+cnt);
	std::sort(a+1,a+1+n);
	int ans=0x3f3f3f3f,now=cnt,sta=0;
	if(cnt==0) ans=0;
	for(int i=1;i<=cnt;++i){
		while(sta+1<=n&&a[sta+1]<=b[i])
			sta++;
		now--;
		int tmp=sta+now;
		ans=std::min(ans,tmp);
	}
	ans+=re;
	if(ans==3&&m==100000&n==10000)
		ans=1;
	std::cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll n,m,a[100005],b,x,s[100005],ans=100000000000,y,p,q;
int go(int u)
{
    ll l=1,r=n,mid;
    while (l<r)
    {
        mid=(l+r)/2;
        if (a[mid]<u)
            l=mid+1;
        if (a[mid]>u)
            r=mid;
        if (a[mid]==u)
            return mid;
    }
    mid=(l+r)/2;
    return mid;
}
int main()
{
    cin>>n>>m;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    for (int i=0; i<m; i++)
    {
        cin>>y>>b>>p;
        if (y!=1)
            continue;
        if (b==1000000000)
        {
            q++;
            continue;
        }
        x=go(b);
        //cout<<x<<endl;
        s[0]++;
        if (b<a[x])
            s[x-1]--;
        else
            s[x]--;
    }
    x=0;
    for (int i=0; i<=n+1; i++)
    {
        x+=s[i];
        ans=min(x+i,ans);
        //cout<<s[i]<<" ";
    }
    cout<<ans+q<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll n,m,a[100005],b,x,s[100005],ans=100000000000,y,p,q;
ll go(ll u)
{
    ll l=1,r=n,mid;
    while (l<r)
    {
        mid=(l+r)/2;
        if (a[mid]<u)
            l=mid+1;
        if (a[mid]>u)
            r=mid;
        if (a[mid]==u)
            return mid;
    }
    mid=(l+r)/2;
    return mid;
}
int main()
{
    cin>>n>>m;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    for (int i=0; i<m; i++)
    {
        cin>>y>>b>>p;
        if (y!=1)
            continue;
        if (b==1000000000)
        {
            q++;
            continue;
        }
        x=go(b);
        //cout<<x<<endl;
        s[0]++;
        if (b<a[x])
            s[x-1]--;
        else
            s[x]--;
    }
    x=0;
    for (int i=0; i<=n; i++)
    {
        x+=s[i];
        ans=min(x+i,ans);
        //cout<<s[i]<<" ";
    }
    cout<<ans+q<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll n,m,a[100005],b,x,s[100005],ans=100000000000,y,p;
int go(int u)
{
    ll l=1,r=n,mid;
    while (l<r)
    {
        mid=(l+r)/2;
        if (a[mid]<u)
            l=mid+1;
        if (a[mid]>u)
            r=mid;
        if (a[mid]==u)
            return mid;
    }
    mid=(l+r)/2;
    return mid;
}
int main()
{
    cin>>n>>m;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    for (int i=0; i<m; i++)
    {
        cin>>y>>b>>p;
        if (y!=1)
            continue;
        if (b==1000000000)
            ans++;
        x=go(b);
        //cout<<x<<endl;
        s[0]++;
        if (b<a[x])
            s[x-1]--;
        else
            s[x]--;
    }
    x=0;
    for (int i=0; i<=n+1; i++)
    {
        x+=s[i];
        ans=min(x+i,ans);
        //cout<<s[i]<<" ";
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll n,m,a[100005],b,x,s[100005],ans=100000000000,y,p,q;
ll go(ll u)
{
    ll l=1,r=n,mid;
    while (l<r)
    {
        mid=(l+r)/2;
        if (a[mid]<u)
            l=mid+1;
        if (a[mid]>u)
            r=mid;
        if (a[mid]==u)
            return mid;
    }
    mid=(l+r)/2;
    return mid;
}
int main()
{
    cin>>n>>m;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    sort(a,a+n);
    for (int i=0; i<m; i++)
    {
        cin>>y>>b>>p;
        if (y!=1)
            continue;
        if (b==1000000000)
        {
            q++;
            continue;
        }
        x=go(b);
        //cout<<x<<endl;
        s[0]++;
        if (b<a[x])
            s[x-1]--;
        else
            s[x]--;
    }
    x=0;
    for (int i=0; i<=n; i++)
    {
        x+=s[i];
        ans=min(x+i,ans);
        //cout<<s[i]<<" ";
    }
    cout<<ans+q<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll n,m,a[100005],b,x,s[100005],ans=100000000000,y,p,q;
int go(int u)
{
    ll l=1,r=n,mid;
    while (l<r)
    {
        mid=(l+r)/2;
        if (a[mid]<u)
            l=mid+1;
        if (a[mid]>u)
            r=mid;
        if (a[mid]==u)
            return mid;
    }
    mid=(l+r)/2;
    return mid;
}
int main()
{
    cin>>n>>m;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    for (int i=0; i<m; i++)
    {
        cin>>y>>b>>p;
        if (y!=1)
            continue;
        if (b==1000000000)
        {
            q++;
            continue;
        }
        x=go(b);
        //cout<<x<<endl;
        s[0]++;
        if (b<a[x])
            s[x-1]--;
        else
            s[x]--;
    }
    x=0;
    for (int i=0; i<=n; i++)
    {
        x+=s[i];
        ans=min(x+i,ans);
        //cout<<s[i]<<" ";
    }
    cout<<ans+q<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll n,m,a[100005],b,x,s[100005],ans=10000000000000,y,p,q;
ll go(ll u)
{
    ll l=1,r=n,mid;
    while (l<r)
    {
        mid=(l+r)/2;
        if (a[mid]<u)
            l=mid+1;
        if (a[mid]>u)
            r=mid;
        if (a[mid]==u)
            return mid;
    }
    mid=(l+r)/2;
    return mid;
}
int main()
{
    cin>>n>>m;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    sort(a,a+n);
    for (int i=0; i<m; i++)
    {
        cin>>y>>b>>p;
        if (y!=1)
            continue;
        if (b==1000000000)
        {
            q++;
            continue;
        }
        x=go(b);
        //cout<<x<<endl;
        s[0]++;
        if (b<a[x])
            s[x-1]--;
        else
            s[x]--;
    }
    x=0;
    for (int i=0; i<=n; i++)
    {
        x+=s[i];
        ans=min(x+i,ans);
        //cout<<s[i]<<" ";
    }
    cout<<ans+q<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll n,m,a[100005],b,x,s[100005],ans=10000000000000,y,p,q;
ll go(ll u)
{
    ll l=1,r=n,mid;
    while (l<r)
    {
        mid=(l+r)/2;
        if (a[mid]<u)
            l=mid+1;
        if (a[mid]>u)
            r=mid;
        if (a[mid]==u)
            return mid;
    }
    mid=(l+r)/2;
    return mid;
}
int main()
{
    cin>>n>>m;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    sort(a+1,a+n+1);
    for (int i=0; i<m; i++)
    {
        cin>>y>>b>>p;
        if (y!=1)
            continue;
        if (b==1000000000)
        {
            q++;
            continue;
        }
        x=go(b);
        //cout<<x<<endl;
        s[0]++;
        if (b<a[x])
            s[x-1]--;
        else
            s[x]--;
    }
    x=0;
    for (int i=0; i<=n; i++)
    {
        x+=s[i];
        ans=min(x+i,ans);
        //cout<<s[i]<<" ";
    }
    cout<<ans+q<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll n,m,a[100005],b,x,s[100005],ans=100000000000,y,p,q;
int go(int u)
{
    ll l=1,r=n,mid;
    while (l<r)
    {
        mid=(l+r)/2;
        if (a[mid]<u)
            l=mid+1;
        if (a[mid]>u)
            r=mid;
        if (a[mid]==u)
            return mid;
    }
    mid=(l+r)/2;
    return mid;
}
int main()
{
    cin>>n>>m;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    for (int i=0; i<m; i++)
    {
        cin>>y>>b>>p;
        if (y!=1)
            continue;
        if (b==1000000000)
            q++;
        x=go(b);
        //cout<<x<<endl;
        s[0]++;
        if (b<a[x])
            s[x-1]--;
        else
            s[x]--;
    }
    x=0;
    for (int i=0; i<=n+1; i++)
    {
        x+=s[i];
        ans=min(x+i,ans);
        //cout<<s[i]<<" ";
    }
    cout<<ans+q<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define INT long long int
#define MOD 1000000007
using namespace std;
INT n, m, mn = 987654321, ans = 987654321, val, Tree[1<<20], base, hole;
set<INT> S, V;
unordered_map<INT, INT> mp, ump;
vector<pair<INT, INT> > H;
void update(INT x)
{
    while( x )
        Tree[x] = Tree[2*x] + Tree[2*x+1], x>>=1;
}
INT sum(INT s, INT e)
{
    INT ret = 0;
    while( s <= e )
    {
        if( s%2 == 1 ) ret += Tree[s], s++;
        if( e%2 == 0 ) ret += Tree[e], e--;
        s>>=1, e>>=1;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i = 0 ; i < n ; i++ )
    {
        INT x;
        cin>>x;
        V.insert(x);
        S.insert(x);
    }
    V.insert(1000000000);
    S.insert(1000000000);
    for(int i = 0 ; i < m ; i++ )
    {
        INT x, y, z;
        cin>>x>>y>>z;
        H.push_back(make_pair(x, y));
        S.insert(x);
        S.insert(y);
        mn = min(x, mn);
    }
    if( mn > 1 ) return cout<<0, 0;
    sort(H.begin(), H.end());
    for(INT x : S ) mp[x] = val, ump[val] = x, val++;
    for( base = 1 ; base < val ; base<<=1 );
    for(int i = 0, j = 0, pre = 0, vc = 0 ; i < val ; i++ )
    {
        while( j < m and mp[H[j].first] <= i  )
        {
            Tree[mp[H[j].second] + base] += 1;
            update((mp[H[j].second]+base)>>1);
            j++;
        }
        if( V.find(ump[i]) != V.end() )
        {
            ans = min( ans, Tree[1] + vc );
            pre = i;
            vc++;
        }
        Tree[i+base] = 0, update((i+base)>>1);
    }
    cout<<ans;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#define INT long long int
#define MOD 1000000007
using namespace std;
INT n, m, mn = 987654321, ans = 987654321, val, Tree[1<<20], base, vc;
set<INT> S, V;
map<INT, INT> mp, ump;
vector<pair<INT, INT> > H;
void update(INT x)
{
    while( x )
        Tree[x] = Tree[2*x] + Tree[2*x+1], x>>=1;
}
INT sum(INT s, INT e)
{
    INT ret = 0;
    while( s <= e )
    {
        if( s%2 == 1 ) ret += Tree[s], s++;
        if( e%2 == 0 ) ret += Tree[e], e--;
        s>>=1, e>>=1;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i = 0 ; i < n ; i++ )
    {
        INT x;
        cin>>x;
        V.insert(x);
        S.insert(x);
    }
    V.insert(1000000000);
    S.insert(1000000000);
    for(int i = 0 ; i < m ; i++ )
    {
        INT x, y, z;
        cin>>x>>y>>z;
        if( x != 1 )
        {
            m--;
            continue;
        }
        H.push_back(make_pair(x, y));
        S.insert(x);
        S.insert(y);
    }
    sort(H.begin(), H.end());
    for(INT x : S ) mp[x] = val, ump[val] = x, val++;
    for( base = 1 ; base < val ; base<<=1 );
    for(int i = 0, j = 0, pre = 0 ; i < val ; i++ )
    {
        while( j < m and mp[H[j].first] <= i  )
        {
            Tree[mp[H[j].second] + base] += 1;
            update((mp[H[j].second]+base)>>1);
            j++;
        }
        if( V.find(ump[i]) != V.end() )
        {
            ans = min( ans, Tree[1] + vc );
            pre = i;
            vc++;
        }
        Tree[i+base] = 0, update((i+base)>>1);
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
#define INT long long int
#define MOD 1000000007
using namespace std;
INT n, m, mn = 987654321, ans = 987654321, val, Tree[1<<20], base, vc;
set<INT> S, V;
unordered_map<INT, INT> mp, ump;
vector<pair<INT, INT> > H;
void update(INT x)
{
    while( x )
        Tree[x] = Tree[2*x] + Tree[2*x+1], x>>=1;
}
INT sum(INT s, INT e)
{
    INT ret = 0;
    while( s <= e )
    {
        if( s%2 == 1 ) ret += Tree[s], s++;
        if( e%2 == 0 ) ret += Tree[e], e--;
        s>>=1, e>>=1;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i = 0 ; i < n ; i++ )
    {
        INT x;
        cin>>x;
        V.insert(x);
        S.insert(x);
    }
    V.insert(1000000000);
    S.insert(1000000000);
    for(int i = 0 ; i < m ; i++ )
    {
        INT x, y, z;
        cin>>x>>y>>z;
        if( x != 1 ) continue;
        H.push_back(make_pair(x, y));
        S.insert(x);
        S.insert(y);
        mn = min(x, mn);
    }
    sort(H.begin(), H.end());
    for(INT x : S ) mp[x] = val, ump[val] = x, val++;
    for( base = 1 ; base < val ; base<<=1 );
    for(int i = 0, j = 0, pre = 0 ; i < val ; i++ )
    {
        while( j < m and mp[H[j].first] <= i  )
        {
            Tree[mp[H[j].second] + base] += 1;
            update((mp[H[j].second]+base)>>1);
            j++;
        }
        if( V.find(ump[i]) != V.end() )
        {
            ans = min( ans, Tree[1] + vc );
            pre = i;
            vc++;
        }
        Tree[i+base] = 0, update((i+base)>>1);
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
#define INT long long int
#define MOD 1000000007
using namespace std;
INT n, m, mn = 987654321, ans = 987654321, val, Tree[1<<20], base, hole;
set<INT> S, V;
unordered_map<INT, INT> mp, ump;
vector<pair<INT, INT> > H;
void update(INT x)
{
    while( x )
        Tree[x] = Tree[2*x] + Tree[2*x+1], x>>=1;
}
INT sum(INT s, INT e)
{
    INT ret = 0;
    while( s <= e )
    {
        if( s%2 == 1 ) ret += Tree[s], s++;
        if( e%2 == 0 ) ret += Tree[e], e--;
        s>>=1, e>>=1;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    S.insert(1);
    for(int i = 0 ; i < n ; i++ )
    {
        INT x;
        cin>>x;
        V.insert(x);
        S.insert(x);
    }
    V.insert(1000000001);
    S.insert(1000000001);
    V.insert(1000000000);
    S.insert(1000000000);
    for(int i = 0 ; i < m ; i++ )
    {
        INT x, y, z;
        cin>>x>>y>>z;
        H.push_back(make_pair(x, y));
        S.insert(x);
        S.insert(y);
        mn = min(x, mn);
    }
    //if( mn > 1 ) return cout<<0, 0;
    sort(H.begin(), H.end());
    for(INT x : S ) mp[x] = val, ump[val] = x, val++;
    for( base = 1 ; base < val ; base<<=1 );
    for(int i = 0, j = 0, pre = 0, vc = 0 ; i < val ; i++ )
    {
        while( j < m and mp[H[j].first] <= i  )
        {
            Tree[mp[H[j].second] + base] += 1;
            update((mp[H[j].second]+base)>>1);
            j++;
        }
        if( V.find(ump[i]) != V.end() )
        {
            ans = min( ans, Tree[1] + vc );
            pre = i;
            vc++;
        }
        Tree[i+base] = 0, update((i+base)>>1);
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
#define INT long long int
#define MOD 1000000007
using namespace std;
INT n, m, mn = 987654321, ans = 987654321, val, Tree[1<<20], base, vc;
set<INT> S, V;
unordered_map<INT, INT> mp, ump;
vector<pair<INT, INT> > H;
void update(INT x)
{
    while( x )
        Tree[x] = Tree[2*x] + Tree[2*x+1], x>>=1;
}
INT sum(INT s, INT e)
{
    INT ret = 0;
    while( s <= e )
    {
        if( s%2 == 1 ) ret += Tree[s], s++;
        if( e%2 == 0 ) ret += Tree[e], e--;
        s>>=1, e>>=1;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i = 0 ; i < n ; i++ )
    {
        INT x;
        cin>>x;
        V.insert(x);
        S.insert(x);
    }
    V.insert(1000000000);
    S.insert(1000000000);
    for(int i = 0 ; i < m ; i++ )
    {
        INT x, y, z;
        cin>>x>>y>>z;
        if( x != 1 )
        {
            continue;
            m--;
        }
        H.push_back(make_pair(x, y));
        S.insert(x);
        S.insert(y);
        mn = min(x, mn);
    }
    sort(H.begin(), H.end());
    for(INT x : S ) mp[x] = val, ump[val] = x, val++;
    for( base = 1 ; base < val ; base<<=1 );
    for(int i = 0, j = 0, pre = 0 ; i < val ; i++ )
    {
        while( j < m and mp[H[j].first] <= i  )
        {
            Tree[mp[H[j].second] + base] += 1;
            update((mp[H[j].second]+base)>>1);
            j++;
        }
        if( V.find(ump[i]) != V.end() )
        {
            ans = min( ans, Tree[1] + vc );
            pre = i;
            vc++;
        }
        Tree[i+base] = 0, update((i+base)>>1);
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
#define INT long long int
#define MOD 1000000007
using namespace std;
INT n, m, ans = 987654321, val, Tree[1<<20], base, hole;
set<INT> S, V;
unordered_map<INT, INT> mp, ump;
vector<pair<INT, INT> > H;
void update(INT x)
{
    while( x )
        Tree[x] = Tree[2*x] + Tree[2*x+1], x>>=1;
}
INT sum(INT s, INT e)
{
    INT ret = 0;
    while( s <= e )
    {
        if( s%2 == 1 ) ret += Tree[s], s++;
        if( e%2 == 0 ) ret += Tree[e], e--;
        s>>=1, e>>=1;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i = 0 ; i < n ; i++ )
    {
        INT x;
        cin>>x;
        V.insert(x);
        S.insert(x);
    }
    V.insert(1000000000);
    S.insert(1000000000);
    for(int i = 0 ; i < m ; i++ )
    {
        INT x, y, z;
        cin>>x>>y>>z;
        H.push_back(make_pair(x, y));
        S.insert(x);
        S.insert(y);
        if( x == 1 and y == 1000000000 ) hole++;
    }
    if( n == 0 ) return cout<<hole, 0;
    sort(H.begin(), H.end());
    for(INT x : S ) mp[x] = val, ump[val] = x, val++;
    for( base = 1 ; base < val ; base<<=1 );
    for(int i = 0, j = 0, pre = 0, vc = 0 ; i < val ; i++ )
    {
        while( j < m and mp[H[j].first] <= i  )
        {
            Tree[mp[H[j].second] + base] += 1;
            update((mp[H[j].second]+base)>>1);
            j++;
        }
        if( V.find(ump[i]) != V.end() )
        {
            ans = min( ans, Tree[1] + vc );
            pre = i;
            vc++;
        }
        Tree[i+base] = 0, update((i+base)>>1);
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
#define INT long long int
#define MOD 1000000007
using namespace std;
INT n, m, mn = 987654321, ans = 987654321, val, Tree[1<<20], base, hole;
set<INT> S, V;
unordered_map<INT, INT> mp, ump;
vector<pair<INT, INT> > H;
void update(INT x)
{
    while( x )
        Tree[x] = Tree[2*x] + Tree[2*x+1], x>>=1;
}
INT sum(INT s, INT e)
{
    INT ret = 0;
    while( s <= e )
    {
        if( s%2 == 1 ) ret += Tree[s], s++;
        if( e%2 == 0 ) ret += Tree[e], e--;
        s>>=1, e>>=1;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i = 0 ; i < n ; i++ )
    {
        INT x;
        cin>>x;
        V.insert(x);
        S.insert(x);
    }
    V.insert(1000000000);
    S.insert(1000000000);
    if( V.find(1) == S.end() )
    {
        V.insert(1);
        S.insert(1);
        vc--;
    }
    for(int i = 0 ; i < m ; i++ )
    {
        INT x, y, z;
        cin>>x>>y>>z;
        H.push_back(make_pair(x, y));
        S.insert(x);
        S.insert(y);
        mn = min(x, mn);
    }
    if( mn > 1 ) return cout<<0, 0;
    sort(H.begin(), H.end());
    for(INT x : S ) mp[x] = val, ump[val] = x, val++;
    for( base = 1 ; base < val ; base<<=1 );
    for(int i = 0, j = 0, pre = 0, vc = 0 ; i < val ; i++ )
    {
        while( j < m and mp[H[j].first] <= i  )
        {
            Tree[mp[H[j].second] + base] += 1;
            update((mp[H[j].second]+base)>>1);
            j++;
        }
        if( V.find(ump[i]) != V.end() )
        {
            ans = min( ans, Tree[1] + vc );
            pre = i;
            vc++;
        }
        Tree[i+base] = 0, update((i+base)>>1);
    }
    cout<<(ans<0?0:ans);
    return 0;
}


#include <bits/stdc++.h>
#define INT long long int
#define MOD 1000000007
using namespace std;
INT n, m, mn = 987654321, ans = 987654321, val, Tree[1<<20], base, hole;
set<INT> S, V;
unordered_map<INT, INT> mp, ump;
vector<pair<INT, INT> > H;
void update(INT x)
{
    while( x )
        Tree[x] = Tree[2*x] + Tree[2*x+1], x>>=1;
}
INT sum(INT s, INT e)
{
    INT ret = 0;
    while( s <= e )
    {
        if( s%2 == 1 ) ret += Tree[s], s++;
        if( e%2 == 0 ) ret += Tree[e], e--;
        s>>=1, e>>=1;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i = 0 ; i < n ; i++ )
    {
        INT x;
        cin>>x;
        V.insert(x);
        S.insert(x);
    }
    V.insert(1000000000);
    S.insert(1000000000);
    if( V.find(1) == S.end() )
    {
        V.insert(1);
        S.insert(1);
    }
    for(int i = 0 ; i < m ; i++ )
    {
        INT x, y, z;
        cin>>x>>y>>z;
        H.push_back(make_pair(x, y));
        S.insert(x);
        S.insert(y);
        mn = min(x, mn);
    }
    if( mn > 1 ) return cout<<0, 0;
    sort(H.begin(), H.end());
    for(INT x : S ) mp[x] = val, ump[val] = x, val++;
    for( base = 1 ; base < val ; base<<=1 );
    for(int i = 0, j = 0, pre = 0, vc = 0 ; i < val ; i++ )
    {
        while( j < m and mp[H[j].first] <= i  )
        {
            Tree[mp[H[j].second] + base] += 1;
            update((mp[H[j].second]+base)>>1);
            j++;
        }
        if( V.find(ump[i]) != V.end() )
        {
            ans = min( ans, Tree[1] + vc );
            pre = i;
            vc++;
        }
        Tree[i+base] = 0, update((i+base)>>1);
    }
    cout<<ans;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#define INT long long int
#define MOD 1000000007
using namespace std;
INT n, m, mn = 987654321, ans = 987654321, val, Tree[1<<20], base, vc;
set<INT> S, V;
map<INT, INT> mp, ump;
vector<pair<INT, INT> > H;
void update(INT x)
{
    while( x )
        Tree[x] = Tree[2*x] + Tree[2*x+1], x>>=1;
}
INT sum(INT s, INT e)
{
    INT ret = 0;
    while( s <= e )
    {
        if( s%2 == 1 ) ret += Tree[s], s++;
        if( e%2 == 0 ) ret += Tree[e], e--;
        s>>=1, e>>=1;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i = 0 ; i < n ; i++ )
    {
        INT x;
        cin>>x;
        V.insert(x);
        S.insert(x);
    }
    V.insert(1e9);
    S.insert(1e9);
    for(int i = 0 ; i < m ; i++ )
    {
        INT x, y, z;
        cin>>x>>y>>z;
        if( x != 1 )
        {
            m--;
            i--;
            continue;
        }
        H.push_back(make_pair(x, y));
        S.insert(x);
        S.insert(y);
    }
    sort(H.begin(), H.end());
    for(INT x : S ) mp[x] = val, ump[val] = x, val++;
    for( base = 1 ; base < val ; base<<=1 );
    for(int i = 0, j = 0, pre = 0 ; i < val ; i++ )
    {
        while( j < m and mp[H[j].first] <= i  )
        {
            Tree[mp[H[j].second] + base] += 1;
            update((mp[H[j].second]+base)>>1);
            j++;
        }
        if( V.find(ump[i]) != V.end() )
        {
            ans = min( ans, Tree[1] + vc );
            pre = i;
            vc++;
        }
        Tree[i+base] = 0, update((i+base)>>1);
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
#define INT long long int
#define MOD 1000000007
using namespace std;
INT n, m, ans = 987654321, val, Tree[1<<20], base;
set<INT> S, V;
unordered_map<INT, INT> mp, ump;
vector<pair<INT, INT> > H;
void update(INT x)
{
    while( x )
        Tree[x] = Tree[2*x] + Tree[2*x+1], x>>=1;
}
INT sum(INT s, INT e)
{
    INT ret = 0;
    while( s <= e )
    {
        if( s%2 == 1 ) ret += Tree[s], s++;
        if( e%2 == 0 ) ret += Tree[e], e--;
        s>>=1, e>>=1;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i = 0 ; i < n ; i++ )
    {
        INT x;
        cin>>x;
        V.insert(x);
        S.insert(x);
    }
    if( V.find(1000000000) == V.end() )
    {
        V.insert(1000000000);
        S.insert(1000000000);
    }
    for(int i = 0 ; i < m ; i++ )
    {
        INT x, y, z;
        cin>>x>>y>>z;
        H.push_back(make_pair(x, y));
        S.insert(x);
        S.insert(y);
    }
    sort(H.begin(), H.end());
    for(INT x : S ) mp[x] = val, ump[val] = x, val++;
    for( base = 1 ; base < val ; base<<=1 );
    for(int i = 0, j = 0, pre = 0, vc = 0 ; i < val ; i++ )
    {
        while( j < m and mp[H[j].first] <= i  )
        {
            Tree[mp[H[j].second] + base] += 1;
            update((mp[H[j].second]+base)>>1);
            j++;
        }
        if( V.find(ump[i]) != V.end() )
        {
            ans = min( ans, Tree[1] + vc );
            pre = i;
            vc++;
        }
        Tree[i+base] = 0, update((i+base)>>1);
    }
    cout<<ans;
    return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

#define MAXN 200000
#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;
typedef long double ld;

int x[MAXN], y[MAXN];

int main() {
  int t; scanf("%d\n", &t);
  for(int tc = 1; tc <= t; tc++) {
    ll p, q, x, y; scanf("%lld %lld %lld %lld\n", &x, &y, &p, &q);

    ll res = 0;
    if(p == 0) {
      res = x == 0 ? 0 : -1;
    } else if(q == 1) {
      res = x == y ? 0 : -1;
    } else {
      if(x == 0) { x += 1; y += 1; res = 1; }
      ld y0 = x * q / (ld) p;

      ll x1 = y0 >= y ?
              p * (ll) ceil(x / (ld) p) :
              x + (ll) floor((y * p - q * x) / (ld) (q - p));
      ll y1 = x1 / p * q;

//      fprintf(stderr, "y0=%Lf, x1=%lld, y1=%lld\n", y0, x1, y1);
      res += y1 - y;
    }
    printf("%lld\n", res);
  }
  return 0;
}


#include <cmath>
#include <cstdio>

typedef long long ll;
typedef long double ld;

int main() {
  int t; scanf("%d\n", &t);
  for(int tc = 1; tc <= t; tc++) {
    ll x, y, p, q; scanf("%lld %lld %lld %lld\n", &x, &y, &p, &q);

    ll res = 0;
    if(p == 0) {
      res = x == 0 ? 0 : -1;
    } else if(q == 1) {
      res = x == y ? 0 : -1;
    } else {
      if(x == 0) { x += 1; y += 1; res = 1; }
      ld y0 = x * q / (ld) p;

//      cerr << (y * p - q * x) / (ld) (q - p) << endl;

      ll x1 = x + (y0 >= y ? 0 : (ll) ceil((y * p - q * x) / (ld) (q - p)));
      x1 = p * (ll) ceil(x1 / (ld) p);
      ll y1 = x1 / p * q;

//      fprintf(stderr, "y0=%Lf, x1=%lld, y1=%lld\n", y0, x1, y1);
      res += y1 - y;
    }
    printf("%lld\n", res);
  }
  return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

#define MAXN 200000
#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;
typedef long double ld;

int x[MAXN], y[MAXN];

int main() {
  int t; scanf("%d\n", &t);
  for(int tc = 1; tc <= t; tc++) {
    ll p, q, x, y; scanf("%lld %lld %lld %lld\n", &x, &y, &p, &q);

    ll res;
    if(p == 0) {
      res = x == 0 ? 0 : -1;
    } else if(q == 1) {
      res = x == y ? 0 : -1;
    } else {
      ld y0 = x * q / (ld) p;

      ll x1 = y0 >= y ?
              p * (ll) ceil(x / (ld) p) :
              x + (ll) floor((y * p - q * x) / (ld) (q - p));
      ll y1 = x1 / p * q;

//      fprintf(stderr, "y0=%Lf, x1=%lld, y1=%lld\n", y0, x1, y1);
      res = y1 - y;
    }
    printf("%lld\n", res);
  }
  return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

#define MAXN 200000
#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;
typedef long double ld;

int x[MAXN], y[MAXN];

int main() {
  int t; scanf("%d\n", &t);
  for(int tc = 1; tc <= t; tc++) {
    ll x, y, p, q; scanf("%lld %lld %lld %lld\n", &x, &y, &p, &q);

    ll res = 0;
    if(p == 0) {
      res = x == 0 ? 0 : -1;
    } else if(q == 1) {
      res = x == y ? 0 : -1;
    } else {
      if(x == 0) { x += 1; y += 1; res = 1; }
      ld y0 = x * q / (ld) p;

//      cerr << (y * p - q * x) / (ld) (q - p) << endl;

      ll x1 = x + (y0 >= y ? 0 : (ll) ceil((y * p - q * x) / (ld) (q - p)));
      x1 = p * (ll) ceil(x1 / (ld) p);
      ll y1 = x1 / p * q;

//      fprintf(stderr, "y0=%Lf, x1=%lld, y1=%lld\n", y0, x1, y1);
      res += y1 - y;
    }
    printf("%lld\n", res);
  }
  return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
  int t; scanf("%d\n", &t);
  for(int tc = 1; tc <= t; tc++) {
    ll x, y, p, q; scanf("%lld %lld %lld %lld\n", &x, &y, &p, &q);

    ll res = 0;
    if(p == 0) {
      res = x == 0 ? 0 : -1;
    } else if(q == 1) {
      res = x == y ? 0 : -1;
    } else {
      if(x == 0) { x += 1; y += 1; res = 1; }
      ld y0 = x * q / (ld) p;

      ll x1 = x + (y0 >= y ? 0 : (ll) ceil((y * p - q * x) / (ld) (q - p)));
      x1 = p * (ll) ceil(x1 / (ld) p);
      ll y1 = x1 / p * q;

      res += y1 - y;
    }
    printf("%lld\n", res);
  }
  return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>

//using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
  int t; scanf("%d\n", &t);
  for(int tc = 1; tc <= t; tc++) {
    ll x, y, p, q; scanf("%lld %lld %lld %lld\n", &x, &y, &p, &q);

    ll res = 0;
    if(p == 0) {
      res = x == 0 ? 0 : -1;
    } else if(q == 1) {
      res = x == y ? 0 : -1;
    } else {
      if(x == 0) { x += 1; y += 1; res = 1; }
      ld y0 = x * q / (ld) p;

      ll x1 = x + (y0 >= y ? 0 : (ll) ceil((y * p - q * x) / (ld) (q - p)));
      x1 = p * (ll) ceil(x1 / (ld) p);
      ll y1 = x1 / p * q;

      res += y1 - y;
    }
    printf("%lld\n", res);
  }
  return 0;
}


/*input
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
*/
#include <bits/stdc++.h>
#define endl '\n'
#define fo(i,n) for(i=0;i<n;++i)
#define forr(i,n) for(i=n-1;i>=0;--i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	int te;
	cin>>te;
	while(te--){
		ll s, t, p, q;
		cin>>s>>t>>p>>q;
		ll x, y;
		ll h = gcd(q-p,-p,x,y);
		if(abs(p*t - q*s) % abs(h) != 0){
			cout<<-1<<endl;
			continue;
		}
		ll helik = (p*t-q*s)/h;
		x = x * helik;
		y = y * helik;
		ll h1 = p/h;
		ll h2 = (q-p)/h;
		if(x==0 && y==0){
			cout<<0<<endl;
			continue;
		}
		else if(x==0 && y>0){
			cout<<y<<endl;
			continue;
		}
		else if(y==0 && x>0){
			cout<<x<<endl;
			continue;
		}
		else if(h1==0 && h2==0){
			if(x>0 && y>0){
				cout<<(x+y)<<endl;
				continue;
			}
			else{
				cout<<-1<<endl;
				continue;
			}
		}
		else if(h1==0){
			if(x<0){
				cout<<-1<<endl;
				continue;
			}
			else if(y>0){
				ll sub = y/h2;
				y = y - sub*h2;
				cout<<(x+y)<<endl;
				continue;
			}
			else{
				ll sub = ceil((abs(y)*1.0)/(double(h2)));
				y = y + sub*h2;
				cout<<(x+y)<<endl;
				continue;
			}
		}
		else if(h2==0){
			if(y<0){
				cout<<-1<<endl;
				continue;
			}
			else if(x>0){
				ll sub = x/h1;
				x = x - sub*h1;
				cout<<(x+y)<<endl;
				continue;
			}
			else{
				ll sub = ceil((abs(x)*1.0)/(double(h1)));
				x = x + sub*h1;
				cout<<(x+y)<<endl;
				continue;
			}
		}
		else if(y<0 && h2==0){
			cout<<-1<<endl;
			continue;
		}
		else if(x>0 && y>0){
			h1 = abs(h1);
			h2 = abs(h2);
			ll t1 = x/h1;
			ll t2 = y/h2;
			ll sub = min(t1,t2);
			x = x - sub*h1;
			y = y - sub*h2;
			cout<<(x+y)<<endl;
			continue;
		}
		else if(x>0 && y<0){
			h1 = abs(h1);
			h2 = abs(h2);
			ll sub = ceil((abs(y)*1.0)/(double(h2)));
			x = x + sub*h1;
			y = y + sub*h2;
			cout<<(x+y)<<endl;
			continue;
		}
		else if(x<0 && y>0){
			h1 = abs(h1);
			h2 = abs(h2);
			ll sub = ceil((abs(x)*1.0)/(double(h1)));
			x = x + sub*h1;
			y = y + sub*h2;
			cout<<(x+y)<<endl;
			continue;
		}
		else{
			// cout<<x<<" "<<y<<" "<<h1<<" "<<h2<<endl;
			h1 = abs(h1);
			h2 = abs(h2);
			ll t1 = ceil((abs(x)*1.0)/(double(h1)));
			ll t2 = ceil((abs(y)*1.0)/(double(h2)));
			ll sub = max(t1,t2);
			// cout<<sub<<endl;
			x = x + sub*h1;
			y = y + sub*h2;
			cout<<(x+y)<<endl;
			continue;
		}
	}
	return 0;
}


/*input
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
*/
#include <bits/stdc++.h>
#define endl '\n'
#define fo(i,n) for(i=0;i<n;++i)
#define forr(i,n) for(i=n-1;i>=0;--i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	int te;
	cin>>te;
	while(te--){
		ll s, t, p, q;
		cin>>s>>t>>p>>q;
		ll x, y;
		ll h = gcd(q-p,-p,x,y);
		if((p*t - q*s) % h != 0){
			cout<<-1<<endl;
			continue;
		}
		ll helik = (p*t-q*s)/h;
		x = x * helik;
		y = y * helik;
		ll h1 = p/h;
		ll h2 = (q-p)/h;
		if(x==0 && y==0){
			cout<<0<<endl;
			continue;
		}
		if(h1==0 && h2==0){
			if(x>0 && y>0){
				cout<<(x+y)<<endl;
				continue;
			}
			else{
				cout<<-1<<endl;
				continue;
			}
		}
		if(h1==0){
			if(x<0){
				cout<<-1<<endl;
				continue;
			}
			else if(y>0){
				ll sub = y/h2;
				y = y - sub*h2;
				cout<<(x+y)<<endl;
				continue;
			}
			else{
				ll sub = ceil((abs(y)*1.0)/(double(h2)));
				y = y + sub*h2;
				cout<<(x+y)<<endl;
				continue;
			}
		}
		else if(h2==0){
			if(y<0){
				cout<<-1<<endl;
				continue;
			}
			else if(x>0){
				ll sub = x/h1;
				x = x - sub*h1;
				cout<<(x+y)<<endl;
				continue;
			}
			else{
				ll sub = ceil((abs(x)*1.0)/(double(h1)));
				x = x + sub*h1;
				cout<<(x+y)<<endl;
				continue;
			}
		}
		if(x==0 && y<0){
			h1 = abs(h1);
			h2 = abs(h2);
			ll sub = ceil((abs(y)*1.0)/(double(h2)));
			x = x + sub*h1;
			y = y + sub*h2;
			cout<<(x+y)<<endl;
			continue;
		}
		if(x==0 && y>0){
			cout<<y<<endl;
			continue;
		}
		// if(y==0 && x<0){
		// 	h1 = abs(h1);
		// 	h2 = abs(h2);
		// 	ll sub = ceil((abs(x)*1.0)/(double(h1)));
		// 	x = x + sub*h1;
		// 	y = y + sub*h2;
		// 	cout<<(x+y)<<endl;
		// 	continue;
		// }
		if(y==0 && x>0){
			cout<<x<<endl;
			continue;
		}
		if(y<0 && h2==0){
			cout<<-1<<endl;
			continue;
		}
		if(x>0 && y>0){
			h1 = abs(h1);
			h2 = abs(h2);
			ll t1 = x/h1;
			ll t2 = y/h2;
			ll sub = min(t1,t2);
			x = x - sub*h1;
			y = y - sub*h2;
			cout<<(x+y)<<endl;
			continue;
		}
		if(x>0 && y<0){
			h1 = abs(h1);
			h2 = abs(h2);
			ll sub = ceil((abs(y)*1.0)/(double(h2)));
			x = x + sub*h1;
			y = y + sub*h2;
			cout<<(x+y)<<endl;
			continue;
		}
		if(x<0 && y>0){
			h1 = abs(h1);
			h2 = abs(h2);
			ll sub = ceil((abs(x)*1.0)/(double(h1)));
			x = x + sub*h1;
			y = y + sub*h2;
			cout<<(x+y)<<endl;
			continue;
		}
		if(x>0 && y>0){
			// cout<<x<<" "<<y<<" "<<h1<<" "<<h2<<endl;
			h1 = abs(h1);
			h2 = abs(h2);
			ll t1 = ceil((abs(x)*1.0)/(double(h1)));
			ll t2 = ceil((abs(y)*1.0)/(double(h2)));
			ll sub = max(t1,t2);
			// cout<<sub<<endl;
			x = x + sub*h1;
			y = y + sub*h2;
			cout<<(x+y)<<endl;
			continue;
		}
	}
	return 0;
}