#include <iostream>
int w[11][11];
bool visit[11] = { false, };
int min = 100000000;
void back(int s, int v, int n, int c,int cnt) {
if (cnt == n && min > c + w[v][s] && w[v][s] != 0) {
min = c + w[v][s];
return;
}
visit[v] = true;
for (int i = 0; i < n; i++) {
if (!visit[i] && min > c + w[v][i] && w[v][i] != 0)
back(s, i, n, c + w[v][i], cnt + 1);
}
visit[v] = false;
}
int main() {
int n;
std::cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
std::cin >> w[i][j];
}
back(0, 0, n, 0, 1);
std::cout << min;
return 0;
}