#include using namespace std; using ll = long long; constexpr char newl = '\n'; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector< vector > c(n, vector(n, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> c[i][j]; } } ll sz = 1; vector pow3(n + 1, 1); for (int i = 0; i < n; i++) { sz *= 3; pow3[i + 1] = sz; } ll mask = 1; vector< vector > dp(n, vector(sz, 1e16)); for (int i = 0; i < n; i++) { dp[i][mask] = 0; mask *= 3; } for (int i = 0; i + 1 < sz; i++) { mask = i; for (int j = 0; j < n; j++) { if (mask % 3 != 0) { ll mask2 = i; for (int k = 0; k < n; k++) { if (k != j && mask2 % 3 != 2) { dp[k][i + pow3[k]] = min(dp[k][i + pow3[k]], dp[j][i] + c[j][k]); } mask2 /= 3; } } mask /= 3; } } ll ans = 1e18; for (int i = 0; i < n; i++) { ans = min({ans, dp[i][sz - 1], dp[i][sz - 1 - pow3[i]]}); } cout << ans << newl; return 0; }