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

using namespace std;

struct edge{
	int u;	//?????????
	int v;	//??°??????
	int cost;	//??????
	//???????????????????????§?????§?°???¢????????????
	bool operator<(const edge& another) const {
			return cost < another.cost;
	}
};

const int MAX_N = 100000;
const int MAX_M = 100000;

edge es[MAX_M];
int par[MAX_N];
int rank[MAX_N];

void initial(int n){		//?????????
	for(int i=0;i<n;i++){
		par[i] = i;
		rank[i] = 0;
	}
}

int find(int x){		//??¨??????????±???????
	if(par[x] == x){
		return x;
	}else{
		return par[x] = find(par[x]);
	}
}

void unite(int x,int y){	//x???????????¨??¨y???????????¨?????????
	x = find(x);	//x???????????¨??????????????????x??¨??????
	y = find(y);	//y???????????¨??????????????????y??¨??????
	if(x == y) return;
	if(rank[x] < rank[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(rank[x] == rank[y])
			rank[x]++;
	}
}

bool same(int x,int y){	//x,y???????????¨???????????§?????????
	return find(x) == find(y);
}

bool comp(const edge& e1,const edge& e2){
	return e1.cost < e2.cost;
}

int kruskal(int n,int m){
	initial(n);
	int res = 0;
	for(int i=0;i<m;i++){
		edge e = es[i];
		if(!same(e.u,e.v)){
			unite(e.u,e.v);
			res += e.cost;
		}
	}
	return res;
}

int main(){
	int n,m,j,k,l;
	cin >> n;	//????????°?????\???
	cin >> m;	//?????°?????\???
	for(int i=0;i<m;i++){
		cin >> j >> k >> l;
		es[i].u = j;	es[i].v = k;	es[i].cost = l;
	}
	sort(es,es+m);
	cout << kruskal(n,m) << "\n";
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
using vs = vector<string> ;
#define all(v) v.begin(),v.end()
const int MAX_V = 210;
const int INF = 1e5;
 
int V;
vll G[MAX_V];
int match[MAX_V];
bool used[MAX_V];
 
void add_edge(int u,int v){
  G[u].push_back(v);
  G[v].push_back(u);
}
 
bool dfs(int v){
  used[v]=true;
  rep(i,G[v].size()){
    int u = G[v][i], w = match[u];
    if(w<0 || !used[w] && dfs(w)){
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}
 
int bipartite_matching(){
  int res = 0;
  memset(match, -1, sizeof(match));
  rep(v,V){
    if(match[v]<0){
      memset(used, 0, sizeof(used));
      if(dfs(v)) res++;
    }
  }
  return res;
}
 
int main(){
  cin>>V;
  vector<pair<int,int>> red,blue;
  rep(i,V){
    int a,b;cin>>a>>b;red.push_back(make_pair(a,b));
  }
  rep(i,V){
    int c,d;cin>>c>>d;blue.push_back(make_pair(c,d));
  }
  rep(i,V){
    rep(j,V){
      pair<int,int> r,b;
      r = red[i],b=blue[j];
      if(r.first<b.first && r.second<b.second) add_edge(i,j+V);
    }
  }
  //cout << "グラフ" << endl;
  //rep(i,V)rep(j,G[i].size()) cout<< i << " " << G[i][j]<<endl;
  cout << bipartite_matching() << endl;
}