#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string &s, char c){vector<string> v;int d=0,f=0;string t;for(char c:s){if(!d&&c==',')v.pb(t),t="";else t+=c;if(c=='\"'||c=='\'')f^=1;if(!f&&c=='(')++d;if(!f&&c==')')--d;}v.pb(t);return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
const ll MOD=1e9+7;
typedef ll Cost;
struct Edge{int to,cap,rev;Cost cost;};
typedef vector<Edge> Edges;
typedef vector<vector<Edge> > Graph;

void add_edge(Graph &g,int from,int to,int cap,Cost cost){
  //out(from,to,cap,cost,1);
  g[from].pb((Edge){to,cap,(int)g[to].size(),cost});
  g[to].pb((Edge){from,0,(int)g[from].size()-1,-cost});
}
Cost INF=1e10;
ll min_cost_flow(Graph &g,int s,int t,int f=1e5){
  int V=g.size();
  vector<Cost> dist(V);
  vector<int> used(V),prevv(V),preve(V);
  ll re=0;
  ll res=0;
  int v,i;
  while(f>0){
    fill(all(dist),INF);
    dist[s]=0;
    bool upd=1;
    while(upd){
      upd=0;
      rep(v,V){
        if(dist[v]==INF)continue;
        rep(i,g[v].size()){
          Edge &e=g[v][i];
          if(e.cap>0 && dist[e.to]>dist[v]+e.cost){
            dist[e.to]=dist[v]+e.cost;
            prevv[e.to]=v;
            preve[e.to]=i;
            upd=1;
          }
        }
      }
    }
    if(dist[t]==INF)
      return re;
    int d=f;
    for(v=t;v!=s;v=prevv[v]){
      d=min(d,g[prevv[v]][preve[v]].cap);
    }
    f-=d;
    res+=1ll*d*dist[t];
    for(v=t;v!=s;v=prevv[v]){
      Edge &e=g[prevv[v]][preve[v]];
      e.cap-=d;
      g[v][e.rev].cap+=d;
    }
    MN(re,res);
  }
  return re;
}

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  cin>>n;
  vector<int> a(n),b(n);
  rep(i,n) cin>>a[i]>>b[i];
  //ll sum=accumulate(all(a),0ll)+accumulate(all(b),0ll);
  auto zip=a; zip.insert(zip.end(),all(b));
  sort(all(zip)); UNIQUE(zip);
  int m=zip.size();
  Graph g(n+m+2);
  rep(i,n){
    int x=lower_bound(all(zip),a[i])-zip.begin();
    int y=lower_bound(all(zip),b[i])-zip.begin();
    //out(i,x,y,1);
    add_edge(g,i,n+x,1,-b[i]);
    add_edge(g,i,n+y,1,-a[i]);
    add_edge(g,n+m,i,1,0);
  }
  rep(i,m) add_edge(g,n+i,n+m+1,1,0);
  ll mn=min_cost_flow(g,n+m,n+m+1);
  cout<<-mn<<endl;
  return 0;
}

Measured memory_bytes: 3588