#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

//
#define MN 10010
struct edge{int to,rev;ll cap,cost;
edge(int to,ll cap,ll cost,int rev):to(to),cap(cap),cost(cost),rev(rev){}};
vector<edge> g[MN];
int V_mcf,prevv[MN],preve[MN];
ll h[MN],dist[MN];

void init(int V){
	V_mcf=V;
	rep(i,V)g[i].clear();
}

void add_edge(int from,int to,ll cap,ll cost){
	g[from].pb(edge(to,cap,cost,sz(g[to])));
	g[to].pb(edge(from,0,-cost,sz(g[from])-1));
};

ll min_cost_flow_any(int s,int t){
	ll res=0;
	fill(h,h+V_mcf,0);
	while(1){
		fill(dist,dist+V_mcf,INF);
		dist[s]=0;
		while(1){
			bool update=0;
			rep(i,V_mcf)rep(j,sz(g[i])){
				edge& e=g[i][j];
				if(e.cap>0 && dist[e.to]>dist[i]+e.cost+h[i]-h[e.to]){
					dist[e.to]=dist[i]+e.cost+h[i]-h[e.to];
					prevv[e.to]=i;
					preve[e.to]=j;
					update=1;
				}
			}
			if(!update)break;
		}
		
		if(dist[t]==INF)return res;
		rep(v,V_mcf)h[v]+=dist[v];
		if(h[t]>=0)break;
		ll d=INF;
		for(int v=t;v!=s;v=prevv[v]){
			d=min(d,g[prevv[v]][preve[v]].cap);
		}
		res+=d*h[t];
		for(int v=t;v!=s;v=prevv[v]){
			edge& e=g[prevv[v]][preve[v]];
			e.cap-=d;
			g[v][e.rev].cap+=d;
		}
	}
	return res;
}
//

int N,A[1010],B[1010];
set<int> S;
int id[1000010];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>N;
	rep(i,N){
		cin>>A[i]>>B[i];
		S.insert(A[i]);
		S.insert(B[i]);
	}
	int cur=N;
	foreach(it,S){
		id[*it]=cur++;
	}
	int s=cur,t=s+1;
	init(t+1);
	rep(i,N){
		add_edge(s,i,1,0);
		add_edge(i,id[A[i]],1,-B[i]);
		if(B[i]!=A[i])add_edge(i,id[B[i]],1,-A[i]);
	}
	rep2(i,N,s)add_edge(i,t,1,0);
	cout<<-min_cost_flow_any(s,t)<<endl;
}