import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto N = readln.chomp.to!int;
    auto AB = N.iota.map!(_ => readln.split.map!(to!long).array).array;

    Tuple!(long, int)[] C;

    foreach (ab; AB) {
        foreach (i; 0..2) {
            C ~= tuple(ab[i], i);
        }
    }
    C.sort!"a[0] < b[0]";

    long ans = 0;
    int[] cnt = [0, 0];

    foreach (i; 0..N) {
        ans += C[i][0];
        cnt[C[i][1]] += 1;
    }

    if (cnt[0] == 1 || cnt[1] == 1) {
        long fa1 = -1;
        long fb1 = -1;
        long fa2 = -1;
        long fb2 = -1;

        foreach_reverse (i; 0..N) {
            if (C[i][1] == 0 && fa1 == -1) {
                fa1 = C[i][0];
            } else if (C[i][1] == 1 && fb1 == -1) {
                fb1 = C[i][0];
            }
        }

        foreach (i; N..N*2) {
            if (C[i][1] == 0 && fa2 == -1) {
                fa2 = C[i][0];
            } else if (C[i][1] == 1 && fb2 == -1) {
                fb2 = C[i][0];
            }
        }

        ans = min(ans - fa1 + fb2, ans - fb1 + fa2);
    }

    ans.writeln;
}
