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

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

ll readLL(){
	ll i;
	scanf("%lld",&i);
	return i;
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

namespace MinCostFlow{
	const int inf=1145141919;
	struct Edge{
		int to,rev,cost,cap;
	};
	vector<vector<Edge>> g;
	int n;
	vi h,dist,prevv,preve;
	void Init(int _n){
		n=_n;
		g.assign(n,vector<Edge>());
		h.assign(n,0);
		dist.assign(n,0);
		prevv.assign(n,0);
		preve.assign(n,0);
	}
	void AddEdge(int from,int to,int cost,int cap){
		g[from].PB({to,(int)g[to].size(),cost,cap});
		g[to].PB({from,(int)g[from].size()-1,-cost,0});
	}
	pii go(int s,int t,int f){
		priority_queue<pii,vector<pii>,greater<pii>> q;
		fill(dist.begin(),dist.end(),inf);
		dist[s]=0;
		q.push(MP(0,s));
		while(!q.empty()){
			int v=q.top().second,d=q.top().first;q.pop();
			if(dist[v]<d)
				continue;
			REP(i,(int)g[v].size()){
				Edge e=g[v][i];
				if(e.cap>0){
					int w=dist[v]+e.cost+h[v]-h[e.to];
					if(w<dist[e.to]){
						dist[e.to]=w;
						q.push(MP(w,e.to));
						prevv[e.to]=v;
						preve[e.to]=i;
					}
				}
			}
		}
		if(dist[t]==inf)
			return MP(0,0);
		REP(i,n)
			h[i]+=dist[i];
		int d=f;
		for(int v=t;v!=s;v=prevv[v])
			chmin(d,g[prevv[v]][preve[v]].cap);
		for(int v=t;v!=s;v=prevv[v]){
			Edge& e=g[prevv[v]][preve[v]];
			e.cap-=d;
			g[e.to][e.rev].cap+=d;
		}
		return MP(d,d*h[t]);
	}
	int Calc(int s,int t,int f){
		int res=0;
		while(f>0){
			pii w=go(s,t,f);
			if(w.first==0)
				return inf;
			f-=w.first;
			res+=w.second;
		}
		return res;
	}
}

signed main(){
	int n=read();
	vi cmp;
	vector<pii> t;
	REP(i,n){
		int a=read(),b=read();
		cmp.PB(a);
		cmp.PB(b);
		t.PB(MP(a,b));
	}
	sort(ALL(cmp));
	cmp.erase(unique(ALL(cmp)),cmp.end());
	MinCostFlow::Init(1+n+cmp.size()+1);
	REP(i,n)
		MinCostFlow::AddEdge(0,1+i,0,1);
	REP(i,n){
		MinCostFlow::AddEdge(1+i,1+n+(lower_bound(ALL(cmp),t[i].first)-cmp.begin()),1000000-t[i].second,1);
		MinCostFlow::AddEdge(1+i,1+n+(lower_bound(ALL(cmp),t[i].second)-cmp.begin()),1000000-t[i].first,1);
		MinCostFlow::AddEdge(1+i,1+n+cmp.size(),1000000,1);
	}
	REP(i,cmp.size())
		MinCostFlow::AddEdge(1+n+i,1+n+cmp.size(),0,1);
	int mcf=MinCostFlow::Calc(0,1+n+cmp.size(),n);
	cout<<1000000*n-mcf<<endl;
}

Measured memory_bytes: 3412