#include <iostream>
#include <algorithm>

int factorial(int n) {
    if (n == 0)
        return 1;
    return n * factorial(n - 1);
}

bool checkSatisfiesCondition(int a[], int n) {
    for (int i = 0; i < n; ++i) {
        bool checkAfter = false, checkBefore = false;

        for (int j = i + 1; j < n; ++j) {
            if (a[j] < a[i]) checkAfter = true;
        }
        for (int j = i - 1; j >= 0; --j) {
            if (a[j] < a[i]) checkBefore = true;
        }

        if (checkAfter && checkBefore)
            return false;
    }

    return true;
}

int main() {

    int n, w[1010][1010], a[1010];
    std::cin >> n;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            std::cin >> w[i][j];
        }
    }

    for (int i = 0; i < n; ++i) a[i] = i;

    int ans = 1e9;
    int factn = factorial(n);
    int ansArray[1010];

    while (factn--) {
        int curCnt = 0;
        for (int i = 1; i < n; ++i) {
            curCnt += w[a[i]][a[i - 1]];
        }

        bool satisfiesCondition = checkSatisfiesCondition(a, n);

        std::next_permutation(a, a + n);
        if (satisfiesCondition)
            ans = std::min(ans, curCnt);
    }
    
    std::cout << ans;
}