#include <math.h>
#include <bits/stdc++.h>//一括で読み込み
typedef long long ll;
using namespace std;
 
const int INF = 1 << 28;
 
struct Primal_Dual
{
  typedef pair<int, int> Pi;
  
  struct edge
  {
    int to, cap, cost, rev;
  };
  vector<vector<edge>> graph;
  vector<int> potential, min_cost, prevv, preve;
  
  Primal_Dual(int V):graph(V){}
  
  void add_edge(int from, int to, int cap, int cost)
  {
    graph[from].push_back((edge){to, cap, cost, (int)graph[to].size()});
    graph[to].push_back((edge){from, 0, -cost, (int)graph[from].size() - 1});
  }
  
  int min_cost_flow(int s,int t,int f)
  {
     
    int V = graph.size(), ret = 0;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;
    potential.assign(V, 0);
    prevv.assign(V, -1);
    preve.assign(V, -1);
 
    while(f > 0)
    {
      min_cost.assign(V, INF);
 
      que.push(Pi(0, s));
      min_cost[s] = 0;
      while(!que.empty())
      {
        Pi p = que.top(); que.pop();
        if(min_cost[p.second] < p.first) continue;
        for(int i = 0; i < graph[p.second].size(); i++)
        {
          edge& e = graph[p.second][i];
          int nextCost = min_cost[p.second] + e.cost + potential[p.second] - potential[e.to];
          if(e.cap > 0 && min_cost[e.to] > nextCost)
          {
            min_cost[e.to] = nextCost;
            prevv[e.to] = p.second, preve[e.to] = i;
            que.push(Pi(min_cost[e.to], e.to));
 
          }
        }
      }
 
      if(min_cost[t] == INF) return(ret);
      for(int v = 0; v < V; v++) potential[v] += min_cost[v];
      int addflow = f;
      for(int v = t; v != s; v = prevv[v])
      {
        addflow = min(addflow, graph[prevv[v]][preve[v]].cap);
      }
      f -= addflow;
      ret += addflow * potential[t];
      for(int v = t; v != s; v = prevv[v])
      {
        edge& e = graph[prevv[v]][preve[v]];
        e.cap -= addflow;
        graph[v][e.rev].cap += addflow;
      }
    }
    return(ret);
  }
};
 
int main()
{
  int n, a[1010], b[1010], aa[1010], bb[1010];
  cin >> n;
  vector<int> nums;
  
  for(int i = 0; i < n; i++)
  {
    cin >> a[i] >> b[i];
    nums.push_back(a[i]);
    nums.push_back(b[i]);
  }
  sort(nums.begin(), nums.end());
  nums.erase(unique(nums.begin(), nums.end()), nums.end());
  
  int s = n+nums.size();
  int g = s+1;
 
  Primal_Dual MCF(g+1);//最小費用流（頂点数）

  for(int i = 0; i < nums.size(); i++)
  {
    MCF.add_edge(s, i, 1, 0);//辺の始点、終点、容量、流量1あたりのコスト（負でも良い）
    //cout << s << " " << i << " " << 1 << " " << 0 << endl;
  }
  
  for(int i = 0; i < n; i++)
  {
    aa[i] = lower_bound(nums.begin(), nums.end(), a[i]) - nums.begin();
    bb[i] = lower_bound(nums.begin(), nums.end(), b[i]) - nums.begin();
    //cout << aa[i] << " " << nums.size()+i << " " << 1 << " " << -nums[aa[i]] << endl;
    //cout << bb[i] << " " << nums.size()+i << " " << 1 << " " << -nums[bb[i]] << endl;
    //cout << nums.size()+i << " " << g << " " << 1 << " " << 0 << endl;
    MCF.add_edge(aa[i], nums.size()+i, 1, -nums[bb[i]]);
    MCF.add_edge(bb[i], nums.size()+i, 1, -nums[aa[i]]);
    MCF.add_edge(nums.size()+i, g, 1, 0);
  }

  //cout << s << " " << g << " " << INF << " " << 0 << endl;
  MCF.add_edge(s, g, INF, 0);
  cout << -MCF.min_cost_flow(s, g, n) << endl;//最小費用流を求める（始点、終点、流量）
}


Measured memory_bytes: 3456