#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <functional>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

int64_t imax(const int64_t a, const int64_t b) { return std::max(a, b); } // std::max, std::min は型が違うとエラーになるため、ラッパーを作る。
int64_t imin(const int64_t a, const int64_t b) { return std::min(a, b); }

#define rep(i, begin, end) for(int64_t i = (begin); i <= (end); i++)
#define rev(i, begin, end) for(int64_t i = (begin); (end) <= i; i--)

#define input1(begin, end, v1) v1.resize((end)+1); for (int i = (begin); i <= (end); i++) { std::cin >> v1[i]; }
#define input2(begin, end, v1, v2) v1.resize((end)+1); v2.resize((end)+1); for (int i = (begin); i <= (end); i++) { std::cin >> v1[i] >> v2[i]; } 
#define input3(begin, end, v1, v2, v3) v1.resize((end)+1); v2.resize((end)+1); v3.resize((end)+1); for (int i = (begin); i <= (end); i++) { std::cin >> v1[i] >> v2[i] >> v3[i]; } 

std::vector<int> irange(const int begin, const int end) {
    std::vector<int> ret; for (int i = begin; i <= end; i++) { ret.push_back(i); }
    return ret;
}

template <typename T>
void printvec(const std::vector<T>& vec) {
    for (int i = 0; i < vec.size(); i++) { std::cout << vec[i] << " "; } std::cout << std::endl;
}

int N;
//int128_t ;
//std::vector<int> ;
std::vector<int128_t> A, B;
//std::string ;
//std::vector<std::string> ;
//double ;
//std::vector<double> ;

struct elem {
    int id;
    int c;
    int128_t v;
    elem(int _id, int _c, int128_t _v) { id = _id; c = _c; v = _v; }
};

const int MAX_N = 1e5 + 10;
int cnt[MAX_N][2] = {};

int main(int argc, char **argv){
    std::cin >> N;

    input2(1, N, A, B);

    std::vector<elem> vec;
    rep (i, 1, N) {
        vec.push_back(elem(i, 0, A[i]));
        vec.push_back(elem(i, 1, B[i]));
    }
    
    std::sort(vec.begin(), vec.end(), [&](elem& x, elem& y){
        return x.v < y.v;
    });

    int128_t tmp = 0;
    rep (i, 0, N - 1) {
        auto& e = vec[i];
        tmp += e.v;
        cnt[e.id][e.c] = 1;
    }

    int both = 0;
    int ca = 0;
    int cb = 0;
    rep (i, 1, N) {
        if (cnt[i][0] + cnt[i][1] == 2) {
            both++;
        } else if (cnt[i][0]) {
            ca++;
        } else if (cnt[i][1]) {
            cb++;
        }
    }

    if (0 < both || ca == 0 || cb == 0) {
        std::cout << tmp << std::endl;
    } else {
        if (vec[N-1].id != vec[N].id) {
            std::cout << tmp - vec[N-1].v + vec[N].v << std::endl;
        } else {
            int128_t c1 = tmp - vec[N-2].v + vec[N].v;
            int128_t c2 = tmp - vec[N-1].v + vec[N+1].v;
            std::cout << imin(c1, c2) << std::endl;
        }
    }

    return 0;
}



Measured memory_bytes: 13548