#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
using namespace std;

const int INF = 1e9;

struct edge {int to, cap, cost, rev;};

int V;
const int MAX_V = 3010;
vector<edge> G[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V], preve[MAX_V];

void add_edge(int from, int to, int cap, int cost){
  G[from].push_back((edge){to, cap, cost, (int)G[to].size()});
  G[to].push_back((edge){from, 0, -cost, (int)G[from].size()-1});
}

int min_cost_flow(int s, int t, int f){
  int res = 0;
  fill(h, h+V, 0);
  while(f > 0){
    priority_queue< pair<int,int>, vector< pair<int,int> >, greater< pair<int,int> > > que;
    fill(dist, dist+V, INF);
    dist[s] = 0;
    que.emplace(0, s);
    while(!que.empty()){
      pair<int,int> p = que.top();
      que.pop();
      int v = p.second;
      if(dist[v] < p.first) continue;
      for(int i = 0; i < G[v].size(); ++i){
        edge &e = G[v][i];
        if(e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]){
          dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
          prevv[e.to] = v;
          preve[e.to] = i;
          que.emplace(dist[e.to], e.to);
        }
      }
    }
    if(dist[t] == INF) return -1;
    for(int v = 0; v < V; ++v) h[v] += dist[v];
    int d = f;
    for(int v = t; v != s; v = prevv[v]){
      d = min(d, G[prevv[v]][preve[v]].cap);
    }
    f -= d;
    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 main(){
  int V_;
  cin >> V_;
  map<int, int> M;
  vector<int> A(V_), B(V_);
  M[0] = 1;
  int S = 0;
  for(int i = 0; i < V_; ++i){
    cin >> A[i] >> B[i];
    S += A[i] + B[i];
    M[A[i]] = 1;
    M[B[i]] = 1;
  }
  
  int k = V_;
  for(auto itr = M.begin(); itr != M.end(); ++itr){
    itr->second = k;
    ++k;
  }
  
  int s = V_ + M.size(), t = s + 1;

  for(int i = 0; i < V_; ++i){
    add_edge(i, M[A[i]], 1, A[i]);
    add_edge(i, M[B[i]], 1, B[i]);
    add_edge(i, M[0], 1, A[i] + B[i]);
    add_edge(s, i, 1, 0);
  }
  V = t+1;
  add_edge(V_, t, V_, 0);
  for(int i = V_+1; i < s; ++i) add_edge(i, t, 1, 0);

  cout << S - min_cost_flow(s, t, V_) << endl;
  
  return 0;
}



