#pragma GCC optimize("Ofast")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = (ll)1e9 + 7;
const int inf = 1e9;
typedef pair<int, int> ii;
typedef pair<int, int> i2;
typedef pair<ll, int> lli;
typedef pair<ll, ll> ll2;

//							#define CUA
const int N=1e6+10; //
const ll base = 29;
ll hashFromLeft[N], hashFromRight[N];
ll bpow[N];
string s;
int n;
//i<=j
ll sub(ll a, ll b) { return (a + mod - b) % mod; }
ll mul(ll a, ll b) {
	return ((a%mod)*(b%mod)) % mod;
}
ll hl(int i, int j) {
	if (i == 0) return hashFromLeft[j];
	ll cax = mul(hashFromLeft[i - 1], bpow[j - i + 1]);
	return sub(hashFromLeft[j], cax);
}
ll hr(int i, int j) {
	if (j == n - 1) return hashFromRight[i];
	ll cax = mul(hashFromRight[j + 1], bpow[j - i + 1]); //TO BE CHECKED
	return sub(hashFromRight[i], cax);
}
bool palin(int l, int r) {
	if (l == r) return true;
	if (l > r) return false;
	ll cax = hl(l, r);
	ll loz = hr(l, r);
	return cax == loz;
}
string concua(int l, int r) {
	if (l > r) return string("");
	if (l == r) return string("") + s[l];
	if (s[l] == s[r]) {
		string tmp = concua(l + 1, r - 1);
		return string("") + s[l] + tmp + s[r];
	}
	int k = 1, len = 1;
	for (int i=l+1; i<=r; ++i)
		if (palin(l, i) && i-l+1>len) {
			len = i - l + 1;
			k = len;
		}
	for (int i=r-1; i>=l; --i)
		if (palin(i, r) && r - i + 1 > len) {
			len = r - i + 1;
			k = -len;
		}
	string ans("");
	if (k > 0) {
		for (int i = l; i <= l + len-1; ++i) ans += s[i];
	}
	else {
		for (int i = r-len+1; i <= r; ++i) ans += s[i];
	}
	return ans;
}
int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef CUA
	ifstream fin; fin.open("input.txt");
	ofstream fout; fout.open("output.txt");
	if (fin.is_open()) {
		cin.rdbuf(fin.rdbuf());
	}
	if (fout.is_open()) {
		cout.rdbuf(fout.rdbuf());
	}
#endif //CUA

	//MAIN CODE HERE
	//MAIN CODE HERE NHA
	//DKM NOI MAIN CODE HERE MA CO NGHE KHONG???
	int t; cin >> t;
	bpow[0] = 1LL; for (int i = 1; i < N; ++i) bpow[i] = (bpow[i - 1] * base) % mod;
	while (t--) {
		cin >> s; n = s.length();
		hashFromLeft[0] = s[0] - 'a' + 1;
		for (int i = 1; i < n; ++i) hashFromLeft[i] = (hashFromLeft[i - 1] * base + (s[i] - 'a' + 1)) % mod;
		hashFromRight[n] = 0LL;
		for (int i = n-1; i >= 0; --i) hashFromRight[i] = (hashFromRight[i + 1] * base + (s[i] - 'a' + 1)) % mod;
		string ans = concua(0, n - 1);
		cout << ans << '\n';
	}

#ifdef CUA
	fin.close(); fout.close();
#endif //CUA

}


//#pragma GCC optimize("Ofast")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = (ll)1e9 + 7;
const int inf = 1e9;
typedef pair<int, int> ii;
typedef pair<int, int> i2;
typedef pair<ll, int> lli;
typedef pair<ll, ll> ll2;

//							#define CUA
const int N=1e6+10; //
const ll base = 29;
ll hashFromLeft[N], hashFromRight[N];
ll bpow[N];
string s;
int n;
//i<=j
ll sub(ll a, ll b) { return (a + mod - b) % mod; }
ll mul(ll a, ll b) {
	return ((a%mod)*(b%mod)) % mod;
}
ll hl(int i, int j) {
	if (i == 0) return hashFromLeft[j];
	ll cax = mul(hashFromLeft[i - 1], bpow[j - i + 1]);
	return sub(hashFromLeft[j], cax);
}
ll hr(int i, int j) {
	if (j == n - 1) return hashFromRight[i];
	ll cax = mul(hashFromRight[j + 1], bpow[j - i + 1]); //TO BE CHECKED
	return sub(hashFromRight[i], cax);
}
bool palin(int l, int r) {
	if (l == r) return true;
	if (l > r) return false;
	ll cax = hl(l, r);
	ll loz = hr(l, r);
	return cax == loz;
}
string concua(int l, int r) {
	if (l > r) return string("");
	if (l == r) return string("") + s[l];
	if (s[l] == s[r])
		return string("") + s[l] + concua(l + 1, r - 1) + s[r];
	int k = 1, len = 1;
	for (int i=l+1; i<=r; ++i)
		if (palin(l, i) && i-l+1>len) {
			len = i - l + 1;
			k = len;
		}
	for (int i=r-1; i>=l; --i)
		if (palin(i, r) && r - i + 1 > len) {
			len = r - i + 1;
			k = -len;
		}
	string ans("");
	if (k > 0) {
		for (int i = l; i < l + k; ++i) ans += s[i];
	}
	else {
		for (int i = r + k + 1; i <= r; ++i) ans += s[i];
	}
	return ans;
}
int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef CUA
	ifstream fin; fin.open("input.txt");
	ofstream fout; fout.open("output.txt");
	if (fin.is_open()) {
		cin.rdbuf(fin.rdbuf());
	}
	if (fout.is_open()) {
		cout.rdbuf(fout.rdbuf());
	}
#endif //CUA

	//MAIN CODE HERE
	//MAIN CODE HERE NHA
	//DKM NOI MAIN CODE HERE MA CO NGHE KHONG???
	int t; cin >> t;
	bpow[0] = 1LL; for (int i = 1; i < N; ++i) bpow[i] = (bpow[i - 1] * base) % mod;
	while (t--) {
		cin >> s; n = s.length();
		hashFromLeft[0] = s[0] - 'a' + 1;
		for (int i = 1; i < n; ++i) hashFromLeft[i] = (hashFromLeft[i - 1] * base + (s[i] - 'a' + 1)) % mod;
		hashFromRight[n] = 0LL;
		for (int i = n-1; i >= 0; --i) hashFromRight[i] = (hashFromRight[i + 1] * base + (s[i] - 'a' + 1)) % mod;
		string ans = concua(0, n - 1);
		cout << ans << '\n';
	}

#ifdef CUA
	fin.close(); fout.close();
#endif //CUA

}


#pragma GCC optimize("Ofast")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = (ll)1e9 + 7;
const int inf = 1e9;
typedef pair<int, int> ii;
typedef pair<int, int> i2;
typedef pair<ll, int> lli;
typedef pair<ll, ll> ll2;

//							#define CUA
const int N=1e6+10; //
const ll base = 29;
ll hashFromLeft[N], hashFromRight[N];
ll bpow[N];
string s;
int n;
//i<=j
ll sub(ll a, ll b) { return (a + mod - b) % mod; }
ll mul(ll a, ll b) {
	return ((a%mod)*(b%mod)) % mod;
}
ll hl(int i, int j) {
	if (i == 0) return hashFromLeft[j];
	ll cax = mul(hashFromLeft[i - 1], bpow[j - i + 1]);
	return sub(hashFromLeft[j], cax);
}
ll hr(int i, int j) {
	if (j == n - 1) return hashFromRight[i];
	ll cax = mul(hashFromRight[j + 1], bpow[j - i + 1]); //TO BE CHECKED
	return sub(hashFromRight[i], cax);
}
bool palin(int l, int r) {
	if (l == r) return true;
	if (l > r) return false;
	ll cax = hl(l, r);
	ll loz = hr(l, r);
	return cax == loz;
}
string concua(int l, int r) {
	if (l > r) return string("");
	if (l == r) return string("") + s[l];
	if (s[l] == s[r]) {
		string tmp = concua(l + 1, r - 1);
		return string("") + s[l] + tmp + s[r];
	}
	int k = 1, len = 1;
	for (int i=l+1; i<=r; ++i)
		if (palin(l, i) && i-l+1>len) {
			len = i - l + 1;
			k = len;
		}
	for (int i=r-1; i>=l; --i)
		if (palin(i, r) && r - i + 1 > len) {
			len = r - i + 1;
			k = -len;
		}
	string ans("");
	if (k > 0) {
		for (int i = l; i < l + len-1; ++i) ans += s[i];
	}
	else {
		for (int i = r-len+1; i <= r; ++i) ans += s[i];
	}
	return ans;
}
int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef CUA
	ifstream fin; fin.open("input.txt");
	ofstream fout; fout.open("output.txt");
	if (fin.is_open()) {
		cin.rdbuf(fin.rdbuf());
	}
	if (fout.is_open()) {
		cout.rdbuf(fout.rdbuf());
	}
#endif //CUA

	//MAIN CODE HERE
	//MAIN CODE HERE NHA
	//DKM NOI MAIN CODE HERE MA CO NGHE KHONG???
	int t; cin >> t;
	bpow[0] = 1LL; for (int i = 1; i < N; ++i) bpow[i] = (bpow[i - 1] * base) % mod;
	while (t--) {
		cin >> s; n = s.length();
		hashFromLeft[0] = s[0] - 'a' + 1;
		for (int i = 1; i < n; ++i) hashFromLeft[i] = (hashFromLeft[i - 1] * base + (s[i] - 'a' + 1)) % mod;
		hashFromRight[n] = 0LL;
		for (int i = n-1; i >= 0; --i) hashFromRight[i] = (hashFromRight[i + 1] * base + (s[i] - 'a' + 1)) % mod;
		string ans = concua(0, n - 1);
		cout << ans << '\n';
	}

#ifdef CUA
	fin.close(); fout.close();
#endif //CUA

}


//#pragma GCC optimize("Ofast")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = (ll)1e9 + 7;
const int inf = 1e9;
typedef pair<int, int> ii;
typedef pair<int, int> i2;
typedef pair<ll, int> lli;
typedef pair<ll, ll> ll2;

//							#define CUA
const int N=1e6+10; //
const ll base = 29;
ll hashFromLeft[N], hashFromRight[N];
ll bpow[N];
string s;
int n;
//i<=j
ll sub(ll a, ll b) { return (a + mod - b) % mod; }
ll mul(ll a, ll b) {
	return ((a%mod)*(b%mod)) % mod;
}
ll hl(int i, int j) {
	if (i == 0) return hashFromLeft[j];
	ll cax = mul(hashFromLeft[i - 1], bpow[j - i + 1]);
	return sub(hashFromLeft[j], cax);
}
ll hr(int i, int j) {
	if (j == n - 1) return hashFromRight[i];
	ll cax = mul(hashFromRight[j + 1], bpow[j - i + 1]); //TO BE CHECKED
	return sub(hashFromRight[i], cax);
}
bool palin(int l, int r) {
	if (l == r) return true;
	if (l > r) return false;
	ll cax = hl(l, r);
	ll loz = hr(l, r);
	return cax == loz;
}
string concua(int l, int r) {
	if (l > r) return string("");
	if (l == r) return string("") + s[l];
	if (s[l] == s[r])
		return string("") + s[l] + concua(l + 1, r - 1) + s[r];
	int k = 1, len = 1;
	for (int i=l+1; i<=r; ++i)
		if (palin(l, i) && i-l+1>len) {
			len = i - l + 1;
			k = len;
		}
	for (int i=r-1; i>=l; --i)
		if (palin(i, r) && r - i + 1 > len) {
			len = r - i + 1;
			k = -len;
		}
	string ans("");
	if (k > 0) {
		for (int i = l; i < l + k; ++i) ans += s[i];
	}
	else {
		for (int i = r + k + 1; i <= r; ++i) ans += s[i];
	}
	return ans;
}
int main() {
	ios::sync_with_stdio(false); cin.tie(0);
#ifdef CUA
	ifstream fin; fin.open("input.txt");
	ofstream fout; fout.open("output.txt");
	if (fin.is_open()) {
		cin.rdbuf(fin.rdbuf());
	}
	if (fout.is_open()) {
		cout.rdbuf(fout.rdbuf());
	}
#endif //CUA

	//MAIN CODE HERE
	//MAIN CODE HERE NHA
	//DKM NOI MAIN CODE HERE MA CO NGHE KHONG???
	int t; cin >> t;
	bpow[0] = 1LL; for (int i = 1; i < N; ++i) bpow[i] = (bpow[i - 1] * base) % mod;
	while (t--) {
		cin >> s; n = s.length();
		hashFromLeft[0] = s[0] - 'a' + 1;
		for (int i = 1; i < n; ++i) hashFromLeft[i] = (hashFromLeft[i - 1] * base + (s[i] - 'a' + 1)) % mod;
		hashFromRight[n] = 0LL;
		for (int i = n-1; i >= 0; --i) hashFromRight[i] = (hashFromRight[i + 1] * base + (s[i] - 'a' + 1)) % mod;
		string ans = concua(0, n - 1);
		cout << ans << endl;
	}

#ifdef CUA
	fin.close(); fout.close();
#endif //CUA

}


#pragma GCC optimize("Ofast")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 998244353;
const int inf = 1e9;
typedef pair<int, int> ii;
typedef pair<int, int> i2;
typedef pair<ll, int> lli;
typedef pair<ll, ll> ll2;

#define mxm(a,b) (a)=max((a),(b))
#define mnm(a,b) (a)=min((a),(b))

//							#define ONLINE_JUDGE
int sz(int l, int r) {
	return r + 1 - l;
}
const int N = 1e6 + 10; //
const ll base = 41;
ll hashFromLeft[N], hashFromRight[N];
ll bpow[N];
string s;
int n;
//i<=j
ll sub(ll a, ll b) { return (a + mod - b) % mod; }
ll mul(ll a, ll b) {
	return ((a%mod)*(b%mod)) % mod;
}
ll hl(int i, int j) {
	if (i == 0) return hashFromLeft[j];
	ll cax = mul(hashFromLeft[i - 1], bpow[j - i + 1]);
	return sub(hashFromLeft[j], cax);
}
ll hr(int i, int j) {
	if (j == n - 1) return hashFromRight[i];
	ll cax = mul(hashFromRight[j + 1], bpow[j - i + 1]); //TO BE CHECKED
	return sub(hashFromRight[i], cax);
}
bool palin(int l, int r) {
	if (l == r) return true;
	if (l > r) return false;
	ll cax = hl(l, r);
	ll loz = hr(l, r);
	return cax == loz;
}
string concua(int l, int r) {
	if (l > r) return string("");
	if (l == r) return string("") + s[l];
	if (s[l] == s[r]) {
		string tmp = concua(l + 1, r - 1);
		return string("") + s[l] + tmp + s[r];
	}
	int k = 1, len = 1;
	for (int i = l + 1; i <= r; ++i)
		if (palin(l, i) && i - l + 1 > len) {
			len = i - l + 1;
			k = len;
		}
	for (int i = r - 1; i >= l; --i)
		if (palin(i, r) && r - i + 1 > len) {
			len = r - i + 1;
			k = -len;
		}
	string ans("");
	if (k > 0) {
		for (int i = l; i <= l + len - 1; ++i) ans += s[i];
	}
	else {
		for (int i = r - len + 1; i <= r; ++i) ans += s[i];
	}
	return ans;
}
int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	ifstream fin; fin.open("input.txt");
	ofstream fout; fout.open("output.txt");
	if (fin.is_open()) {
		cin.rdbuf(fin.rdbuf());
	}
	if (fout.is_open()) {
		cout.rdbuf(fout.rdbuf());
	}
#endif

	//MAIN CODE HERE
	//MAIN CODE HERE NHA
	//DKM NOI MAIN CODE HERE MA CO NGHE KHONG???
	int t; cin >> t;
	bpow[0] = 1LL; for (int i = 1; i < N; ++i) bpow[i] = (bpow[i - 1] * base) % mod;
	while (t--) {
		cin >> s; n = s.length();
		hashFromLeft[0] = s[0] - 'a' + 1;
		for (int i = 1; i < n; ++i) hashFromLeft[i] = (hashFromLeft[i - 1] * base + (s[i] - 'a' + 1)) % mod;
		hashFromRight[n] = 0LL;
		for (int i = n - 1; i >= 0; --i) hashFromRight[i] = (hashFromRight[i + 1] * base + (s[i] - 'a' + 1)) % mod;
		int l = 0, r = n - 1;
		while (l + 1 < r && s[l] == s[r]) {
			l++;
			r--;
		}
		string ans("");
		for (int i = 0; i < l; ++i) ans += s[i];
		string tmp = concua(l, r);
		ans += tmp;
		for (int i = r + 1; i < n; ++i) ans += s[i];
		cout << ans << '\n';
	}

#ifdef CUA
	fin.close(); fout.close();
#endif //CUA

}


#pragma GCC optimize("Ofast")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 998244353;
const int inf = 1e9;
typedef pair<int, int> ii;
typedef pair<int, int> i2;
typedef pair<ll, int> lli;
typedef pair<ll, ll> ll2;

#define mxm(a,b) (a)=max((a),(b))
#define mnm(a,b) (a)=min((a),(b))

//							#define ONLINE_JUDGE
int sz(int l, int r) {
	return r + 1 - l;
}
const int N = 1e6 + 10; //
const ll base = 257;
ll hashFromLeft[N], hashFromRight[N];
ll bpow[N];
string s;
int n;
//i<=j
ll sub(ll a, ll b) { return (a + mod - b) % mod; }
ll mul(ll a, ll b) {
	return ((a%mod)*(b%mod)) % mod;
}
ll hl(int i, int j) {
	if (i == 0) return hashFromLeft[j];
	ll cax = mul(hashFromLeft[i - 1], bpow[j - i + 1]);
	return sub(hashFromLeft[j], cax);
}
ll hr(int i, int j) {
	if (j == n - 1) return hashFromRight[i];
	ll cax = mul(hashFromRight[j + 1], bpow[j - i + 1]); //TO BE CHECKED
	return sub(hashFromRight[i], cax);
}
bool palin(int l, int r) {
	if (l == r) return true;
	if (l > r) return false;
	ll cax = hl(l, r);
	ll loz = hr(l, r);
	return cax == loz;
}
string concua(int l, int r) {
	if (l > r) return string("");
	if (l == r) return string("") + s[l];
	if (s[l] == s[r]) {
		string tmp = concua(l + 1, r - 1);
		return string("") + s[l] + tmp + s[r];
	}
	int k = 1, len = 1;
	for (int i = l + 1; i <= r; ++i)
		if (palin(l, i) && i - l + 1 > len) {
			len = i - l + 1;
			k = len;
		}
	for (int i = r - 1; i >= l; --i)
		if (palin(i, r) && r - i + 1 > len) {
			len = r - i + 1;
			k = -len;
		}
	string ans("");
	if (k > 0) {
		for (int i = l; i <= l + len - 1; ++i) ans += s[i];
	}
	else {
		for (int i = r - len + 1; i <= r; ++i) ans += s[i];
	}
	return ans;
}
int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	ifstream fin; fin.open("input.txt");
	ofstream fout; fout.open("output.txt");
	if (fin.is_open()) {
		cin.rdbuf(fin.rdbuf());
	}
	if (fout.is_open()) {
		cout.rdbuf(fout.rdbuf());
	}
#endif

	//MAIN CODE HERE
	//MAIN CODE HERE NHA
	//DKM NOI MAIN CODE HERE MA CO NGHE KHONG???
	int t; cin >> t;
	bpow[0] = 1LL; for (int i = 1; i < N; ++i) bpow[i] = (bpow[i - 1] * base) % mod;
	while (t--) {
		cin >> s; n = s.length();
		hashFromLeft[0] = s[0] - 'a' + 1;
		for (int i = 1; i < n; ++i) hashFromLeft[i] = (hashFromLeft[i - 1] * base + (s[i] - 'a' + 1)) % mod;
		hashFromRight[n] = 0LL;
		for (int i = n - 1; i >= 0; --i) hashFromRight[i] = (hashFromRight[i + 1] * base + (s[i] - 'a' + 1)) % mod;
		int l = 0, r = n - 1;
		while (l + 1 < r && s[l] == s[r]) {
			l++;
			r--;
		}
		string ans("");
		for (int i = 0; i < l; ++i) ans += s[i];
		string tmp = concua(l, r);
		ans += tmp;
		for (int i = r + 1; i < n; ++i) ans += s[i];
		cout << ans << '\n';
	}

#ifdef CUA
	fin.close(); fout.close();
#endif //CUA

}


#pragma GCC optimize("O3")

#include <bits/stdc++.h>

#define mod 1000000007
#define pb push_back
#define ep emplace_back
#define fr first
#define sc second
#define linf  (((1ll << 62) - 1) << 1)
#define inf (((1 << 30) - 1) << 1)
const double eps = 0.000000001;
#define leps 1e-18
#define mkp make_pair
#define pnode Node*
#define mpi unordered_map<int, int>
#define pii pair<int, int>
#define per(n) for(int i = 0; i < (n); i ++)
#define rep(n) for(int i = n; i >= 0; i --)

typedef long long ll;
std::random_device rd;
std::mt19937_64 mt(rd());
using namespace std;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll binpow(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res = (a * res) % mod;
            n--;
        } else {
            a = (a * a) % mod;
            n >>= 1;
        }
    }
    return res;
}
int n, k;
map<int, int> d[80][80];
ll a[80][80];
int x[11];
int mask[80];

ll ans = linf;

void rec(int h){
    if(h == k) {
        ll sum = 0;
        x[0] = 0;
        x[k] = 0;

        for(int i = 0; i < k; i ++){
            int mn = inf;
            for(auto p : d[x[i]][x[i+1]]){
                if(mask[p.fr]) continue;
                mn = min(mn, p.sc);
            }
            sum += mn;
        }
        ans = min(ans, sum);
        return;
    }
    for(int i = 0; i < n; i ++){
        x[h] = i;
        mask[i] ++;
        rec(h + 1);
        mask[i] --;
    }
};

void solve() {
    cin >> n >> k;

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

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            vector<pii> v;
            for (int z = 0; z < n; z++) {
                if (i != z && j != z){
                    v.pb({a[i][z] + a[z][j], z});
                }
            }
            sort(v.begin(), v.end());

            for(int ii = 0; ii < k; ii ++){
                if(ii >= n - 2) break;
                d[i][j][v[ii].sc] = v[ii].fr;
            }
        }
    }

    k >>= 1;

    fill(mask, mask + n, 0);

    rec(1);

    cout << ans << endl;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t = 1;
//    cin >> t;
    while (t-- > 0) {
        solve();
    }
}


#pragma GCC optimize("O2")

#include <bits/stdc++.h>

#define mod 1000000007
#define pb push_back
#define ep emplace_back
#define fr first
#define sc second
#define linf  (((1ll << 62) - 1) << 1)
#define inf (((1 << 30) - 1) << 1)
const double eps = 0.000000001;
#define leps 1e-18
#define mkp make_pair
#define pnode Node*
#define mpi unordered_map<int, int>
#define pii pair<int, int>
#define per(n) for(int i = 0; i < (n); i ++)
#define rep(n) for(int i = n; i >= 0; i --)

typedef long long ll;
std::random_device rd;
std::mt19937_64 mt(rd());
using namespace std;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll binpow(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res = (a * res) % mod;
            n--;
        } else {
            a = (a * a) % mod;
            n >>= 1;
        }
    }
    return res;
}
int n, k;
unordered_map<int, int> d[80][80];
ll a[80][80];
int x[11];
int mask[80];

ll ans = linf;

void rec(int h){
    if(h == k) {
        ll sum = 0;
        x[0] = 0;
        x[k] = 0;

        for(int i = 0; i < k; i ++){
            int mn = inf;
            for(auto p : d[x[i]][x[i+1]]){
                if(mask[p.fr]) continue;
                mn = min(mn, p.sc);
            }
            sum += mn;
        }
        ans = min(ans, sum);
        return;
    }
    for(int i = 0; i < n; i ++){
        x[h] = i;
        mask[i] ++;
        rec(h + 1);
        mask[i] --;
    }
};

void solve() {
    cin >> n >> k;

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

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            vector<pii> v;
            for (int z = 0; z < n; z++) {
                if (i != z && j != z){
                    v.pb({a[i][z] + a[z][j], z});
                }
            }
            sort(v.begin(), v.end());

            for(int ii = 0; ii < k; ii ++){
                if(ii >= v.size()) break;
                d[i][j][v[ii].sc] = v[ii].fr;
            }
        }
    }

    k >>= 1;

    fill(mask, mask + n, 0);

    rec(1);

    cout << ans << endl;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t = 1;
//    cin >> t;
    while (t-- > 0) {
        solve();
    }
}


#pragma GCC optimize("O3")

#include <bits/stdc++.h>

#define mod 1000000007
#define pb push_back
#define ep emplace_back
#define fr first
#define sc second
#define linf  (((1ll << 62) - 1) << 1)
#define inf (((1 << 30) - 1) << 1)
const double eps = 0.000000001;
#define leps 1e-18
#define mkp make_pair
#define pnode Node*
#define mpi unordered_map<int, int>
#define pii pair<int, int>
#define per(n) for(int i = 0; i < (n); i ++)
#define rep(n) for(int i = n; i >= 0; i --)

typedef long long ll;
std::random_device rd;
std::mt19937_64 mt(rd());
using namespace std;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll binpow(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res = (a * res) % mod;
            n--;
        } else {
            a = (a * a) % mod;
            n >>= 1;
        }
    }
    return res;
}
int n, k;
unordered_map<int, int> d[80][80];
ll a[80][80];
int x[11];
int mask[80];

ll ans = linf;

void rec(int h){
    if(h == k) {
        ll sum = 0;
        x[0] = 0;
        x[k] = 0;

        for(int i = 0; i < k; i ++){
            int mn = inf;
            for(auto p : d[x[i]][x[i+1]]){
                if(mask[p.fr]) continue;
                mn = min(mn, p.sc);
            }
            sum += mn;
        }
        ans = min(ans, sum);
        return;
    }
    for(int i = 0; i < n; i ++){
        x[h] = i;
        mask[i] ++;
        rec(h + 1);
        mask[i] --;
    }
};

void solve() {
    cin >> n >> k;

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

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            vector<pii> v;
            for (int z = 0; z < n; z++) {
                if (i != z && j != z){
                    v.pb({a[i][z] + a[z][j], z});
                }
            }
            sort(v.begin(), v.end());

            for(int ii = 0; ii < k; ii ++){
                if(ii >= v.size()) break;
                d[i][j][v[ii].sc] = v[ii].fr;
            }
        }
    }

    k >>= 1;

    fill(mask, mask + n, 0);

    rec(1);

    cout << ans << endl;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t = 1;
//    cin >> t;
    while (t-- > 0) {
        solve();
    }
}


#pragma GCC optimize("O3")

#include <bits/stdc++.h>

#define mod 1000000007
#define pb push_back
#define ep emplace_back
#define fr first
#define sc second
#define linf  (((1ll << 62) - 1) << 1)
#define inf (((1 << 30) - 1) << 1)
const double eps = 0.000000001;
#define leps 1e-18
#define mkp make_pair
#define pnode Node*
#define mpi unordered_map<int, int>
#define pii pair<int, int>
#define per(n) for(int i = 0; i < (n); i ++)
#define rep(n) for(int i = n; i >= 0; i --)

typedef long long ll;
std::random_device rd;
std::mt19937_64 mt(rd());
using namespace std;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll binpow(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res = (a * res) % mod;
            n--;
        } else {
            a = (a * a) % mod;
            n >>= 1;
        }
    }
    return res;
}
    int n, k;
    map<int, int> d[80][80];
    ll a[80][80];
int x[11];
int mask[80];

ll ans = linf;

void rec(int h){
    if(h == k) {
        ll sum = 0;
        x[0] = 1;
        x[k] = 1;

        for(int i = 0; i < k; i ++){
            int mn = inf;
            for(auto p : d[x[i]][x[i+1]]){
                if(mask[p.fr]) continue;
                mn = min(mn, p.sc);
            }
            sum += mn;
        }
        ans = min(ans, sum);
        return;
    }
    for(int i = 0; i < n; i ++){
        x[h] = i;
        mask[i] ++;
        rec(h + 1);
        mask[i] --;
    }
};

void solve() {
    cin >> n >> k;

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

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            vector<pii> v;
            for (int z = 0; z < n; z++) {
                if (i != z && j != z){
                    v.pb({a[i][z] + a[z][j], z});
                }
            }
            sort(v.begin(), v.end());

            for(int ii = 0; ii < k; ii ++){
                if(ii >= n - 2) break;
                d[i][j][v[ii].sc] = v[ii].fr;
            }
        }
    }

    k >>= 1;

    fill(mask, mask + n, 0);

    rec(1);

    cout << ans << endl;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t = 1;
//    cin >> t;
    while (t-- > 0) {
        solve();
    }
}


#pragma GCC optimize("O1")

#include <bits/stdc++.h>

#define mod 1000000007
#define pb push_back
#define ep emplace_back
#define fr first
#define sc second
#define linf  (((1ll << 62) - 1) << 1)
#define inf (((1 << 30) - 1) << 1)
const double eps = 0.000000001;
#define leps 1e-18
#define mkp make_pair
#define pnode Node*
#define mpi unordered_map<int, int>
#define pii pair<int, int>
#define per(n) for(int i = 0; i < (n); i ++)
#define rep(n) for(int i = n; i >= 0; i --)
#define all(v) v.begin(), v.end()

typedef long long ll;
std::random_device rd;
std::mt19937_64 mt(rd());
using namespace std;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll binpow(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res = (a * res) % mod;
            n--;
        } else {
            a = (a * a) % mod;
            n >>= 1;
        }
    }
    return res;
}
int n, k;
vector<pii> d[80][80];
ll a[80][80];
int x[11];
int mask[80];

ll ans = linf;

void rec(int h){
    if(h == k) {
        ll sum = 0;
        x[0] = 0;
        x[k] = 0;
        for(int i = 0; i < k; i ++){
            int mn = inf;
            for(auto p : d[x[i]][x[i+1]]){
                if(mask[p.sc]) continue;
                mn = p.fr;
                break;
            }
            sum += mn;
        }
        ans = min(ans, sum);
        return;
    }
    for(int i = 0; i < n; i ++){
        x[h] = i;
        mask[i] ++;
        rec(h + 1);
        mask[i] --;
    }
};

void solve() {

    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int z = 0; z < n; z++) {
                if (i != z && j != z){
                    d[i][j].pb({a[i][z] + a[z][j], z});
                }
            }
            sort(all(d[i][j]));
        }
    }

    k >>= 1;
    fill(mask, mask + n, 0);
    rec(1);

    cout << ans << endl;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t = 1;
//    cin >> t;
    while (t-- > 0) {
        solve();
    }
}


#pragma GCC optimize("O1")

#include <bits/stdc++.h>

#define mod 1000000007
#define pb push_back
#define ep emplace_back
#define fr first
#define sc second
#define linf  (((1ll << 62) - 1) << 1)
#define inf (((1 << 30) - 1) << 1)
const double eps = 0.000000001;
#define leps 1e-18
#define mkp make_pair
#define pnode Node*
#define mpi unordered_map<int, int>
#define pii pair<int, int>
#define per(n) for(int i = 0; i < (n); i ++)
#define rep(n) for(int i = n; i >= 0; i --)

typedef long long ll;
std::random_device rd;
std::mt19937_64 mt(rd());
using namespace std;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll binpow(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res = (a * res) % mod;
            n--;
        } else {
            a = (a * a) % mod;
            n >>= 1;
        }
    }
    return res;
}
int n, k;
unordered_map<int, int> d[80][80];
ll a[80][80];
int x[11];
int mask[80];

ll ans = linf;

void rec(int h){
    if(h == k) {
        ll sum = 0;
        x[0] = 0;
        x[k] = 0;

        for(int i = 0; i < k; i ++){
            int mn = inf;
            for(auto p : d[x[i]][x[i+1]]){
                if(mask[p.fr]) continue;
                mn = min(mn, p.sc);
            }
            sum += mn;
        }
        ans = min(ans, sum);
        return;
    }
    for(int i = 0; i < n; i ++){
        x[h] = i;
        mask[i] ++;
        rec(h + 1);
        mask[i] --;
    }
};

void solve() {
    cin >> n >> k;

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

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            vector<pii> v;
            for (int z = 0; z < n; z++) {
                if (i != z && j != z){
                    v.pb({a[i][z] + a[z][j], z});
                }
            }
            sort(v.begin(), v.end());

            for(int ii = 0; ii < k; ii ++){
                if(ii >= v.size()) break;
                d[i][j][v[ii].sc] = v[ii].fr;
            }
        }
    }

    k >>= 1;

    fill(mask, mask + n, 0);

    rec(1);

    cout << ans << endl;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t = 1;
//    cin >> t;
    while (t-- > 0) {
        solve();
    }
}


#pragma GCC optimize("O3")

#include <bits/stdc++.h>

#define mod 1000000007
#define pb push_back
#define ep emplace_back
#define fr first
#define sc second
#define linf  (((1ll << 62) - 1) << 1)
#define inf (((1 << 30) - 1) << 1)
const double eps = 0.000000001;
#define leps 1e-18
#define mkp make_pair
#define pnode Node*
#define mpi unordered_map<int, int>
#define pii pair<int, int>
#define per(n) for(int i = 0; i < (n); i ++)
#define rep(n) for(int i = n; i >= 0; i --)

typedef long long ll;
std::random_device rd;
std::mt19937_64 mt(rd());
using namespace std;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll binpow(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res = (a * res) % mod;
            n--;
        } else {
            a = (a * a) % mod;
            n >>= 1;
        }
    }
    return res;
}
int n, k;
unordered_map<int, int> d[80][80];
ll a[80][80];
int x[11];
int mask[80];

ll ans = linf;

ll U[80][80];

void rec(int h){
    if(h == k) {
        ll sum = 0;
        x[0] = 0;
        x[k] = 0;

        for(int i = 0; i < k; i ++){
            if(U[x[i]][x[i+1]] != inf){
                sum += U[x[i]][x[i+1]];
                continue;
            }
            int mn = inf;
            for(auto p : d[x[i]][x[i+1]]){
                if(mask[p.fr]) continue;
                mn = min(mn, p.sc);
            }
            U[x[i]][x[i+1]] = mn;
            sum += mn;
        }
        ans = min(ans, sum);
        return;
    }
    for(int i = 0; i < n; i ++){
        x[h] = i;
        mask[i] ++;
        rec(h + 1);
        mask[i] --;
    }
};

void solve() {
    cin >> n >> k;

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

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            U[i][j] = inf;
            vector<pii> v;
            for (int z = 0; z < n; z++) {
                if (i != z && j != z){
                    v.pb({a[i][z] + a[z][j], z});
                }
            }
            sort(v.begin(), v.end());

            for(int ii = 0; ii < k; ii ++){
                if(ii >= v.size()) break;
                d[i][j][v[ii].sc] = v[ii].fr;
            }
        }
    }

    k >>= 1;

    fill(mask, mask + n, 0);

    rec(1);

    cout << ans << endl;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t = 1;
//    cin >> t;
    while (t-- > 0) {
        solve();
    }
}


#pragma GCC optimize("O3")

#include <bits/stdc++.h>

#define mod 1000000007
#define pb push_back
#define ep emplace_back
#define fr first
#define sc second
#define linf  (((1ll << 62) - 1) << 1)
#define inf (((1 << 30) - 1) << 1)
const double eps = 0.000000001;
#define leps 1e-18
#define mkp make_pair
#define pnode Node*
#define mpi unordered_map<int, int>
#define pii pair<int, int>
#define per(n) for(int i = 0; i < (n); i ++)
#define rep(n) for(int i = n; i >= 0; i --)

typedef long long ll;
std::random_device rd;
std::mt19937_64 mt(rd());
using namespace std;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll binpow(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res = (a * res) % mod;
            n--;
        } else {
            a = (a * a) % mod;
            n >>= 1;
        }
    }
    return res;
}
int n, k;
map<int, int> d[80][80];
ll a[80][80];
int x[11];
int mask[80];

ll ans = linf;

void rec(int h){
    if(h == k) {
        ll sum = 0;
        x[0] = 0;
        x[k] = 0;

        for(int i = 0; i < k; i ++){
            int mn = inf;
            for(auto p : d[x[i]][x[i+1]]){
                if(mask[p.fr]) continue;
                mn = min(mn, p.sc);
            }
            sum += mn;
        }
        ans = min(ans, sum);
        return;
    }
    for(int i = 0; i < n; i ++){
        x[h] = i;
        mask[i] ++;
        rec(h + 1);
        mask[i] --;
    }
};

void solve() {
    cin >> n >> k;

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

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            vector<pii> v;
            for (int z = 0; z < n; z++) {
                if (i != z && j != z){
                    v.pb({a[i][z] + a[z][j], z});
                }
            }
            sort(v.begin(), v.end());

            for(int ii = 0; ii < k; ii ++){
                if(ii >= v.size()) break;
                d[i][j][v[ii].sc] = v[ii].fr;
            }
        }
    }

    k >>= 1;

    fill(mask, mask + n, 0);

    rec(1);

    cout << ans << endl;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t = 1;
//    cin >> t;
    while (t-- > 0) {
        solve();
    }
}


#pragma GCC optimize("O3")

#include <bits/stdc++.h>

#define mod 1000000007
#define pb push_back
#define ep emplace_back
#define fr first
#define sc second
#define linf  (((1ll << 62) - 1) << 1)
#define inf (((1 << 30) - 1) << 1)
const double eps = 0.000000001;
#define leps 1e-18
#define mkp make_pair
#define pnode Node*
#define mpi unordered_map<int, int>
#define pii pair<int, int>
#define per(n) for(int i = 0; i < (n); i ++)
#define rep(n) for(int i = n; i >= 0; i --)

typedef long long ll;
std::random_device rd;
std::mt19937_64 mt(rd());
using namespace std;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll binpow(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res = (a * res) % mod;
            n--;
        } else {
            a = (a * a) % mod;
            n >>= 1;
        }
    }
    return res;
}
int n, k;
unordered_map<int, int> d[80][80];
ll a[80][80];
int x[11];
int mask[80];

ll ans = linf;

ll U[80][80];

void rec(int h){
    if(h == k) {
        ll sum = 0;
        x[0] = 0;
        x[k] = 0;

        for(int i = 0; i < k; i ++){
            if(U[x[i]][x[i+1]] != linf){
                sum += U[x[i]][x[i+1]];
                continue;
            }
            int mn = inf;
            for(auto p : d[x[i]][x[i+1]]){
                if(mask[p.fr]) continue;
                mn = min(mn, p.sc);
            }
            U[x[i]][x[i+1]] = mn;
            sum += mn;
        }
        ans = min(ans, sum);
        return;
    }
    for(int i = 0; i < n; i ++){
        x[h] = i;
        mask[i] ++;
        rec(h + 1);
        mask[i] --;
    }
};

void solve() {
    cin >> n >> k;

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

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            U[i][j] = linf;
            vector<pii> v;
            for (int z = 0; z < n; z++) {
                if (i != z && j != z){
                    v.pb({a[i][z] + a[z][j], z});
                }
            }
            sort(v.begin(), v.end());

            for(int ii = 0; ii < k; ii ++){
                if(ii >= v.size()) break;
                d[i][j][v[ii].sc] = v[ii].fr;
            }
        }
    }

    k >>= 1;

    fill(mask, mask + n, 0);

    rec(1);

    cout << ans << endl;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t = 1;
//    cin >> t;
    while (t-- > 0) {
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;
const int Maxn=80;
typedef long long ll;
const ll Inf=0x3f3f3f3f3f3f3f3fll;
int a[Maxn+5][Maxn+5];
ll f[2][Maxn+5];
int n,k;
ll ans=Inf;
int vis[Maxn+5];
vector<int> node[2];
int main(){
	mt19937 mt_rand(time(0));
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			scanf("%d",&a[i][j]);
		}
	}
	ll ans=Inf;
	while(1.0*clock()/CLOCKS_PER_SEC<2.9){
		memset(f,0x3f,sizeof f);
		node[0].clear();
		node[1].clear();
		for(int i=2;i<=n;i++){
			vis[i]=mt_rand()&1;
			node[vis[i]].push_back(i);
		}
		node[0].push_back(1);
		f[0][1]=0;
		for(int t=1;t<=k;t++){
			memset(f[t&1],0x3f,sizeof f[t&1]);
			for(int i=0;i<node[(t&1)^1].size();i++){
				for(int j=0;j<node[t&1].size();j++){
					f[t&1][node[t&1][j]]=min(f[t&1][node[t&1][j]],f[(t&1)^1][node[(t&1)^1][i]]+a[node[(t&1)^1][i]][node[t&1][j]]);
				}
			}
		}
		ans=min(ans,f[0][1]);
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int Maxn=80;
typedef long long ll;
const ll Inf=0x3f3f3f3f3f3f3f3fll;
int a[Maxn+5][Maxn+5];
ll f[2][Maxn+5];
int n,k;
ll ans=Inf;
int vis[Maxn+5];
vector<int> node[2];
int main(){
	mt19937 mt_rand(time(0));
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			scanf("%d",&a[i][j]);
		}
	}
	int T=1000;
	ll ans=Inf;
	while(T--){
		srand(rand());
		memset(f,0x3f,sizeof f);
		node[0].clear();
		node[1].clear();
		for(int i=2;i<=n;i++){
			vis[i]=mt_rand()&1;
			node[vis[i]].push_back(i);
		}
		node[0].push_back(1);
		f[0][1]=0;
		for(int t=1;t<=k;t++){
			memset(f[t&1],0x3f,sizeof f[t&1]);
			for(int i=0;i<node[(t&1)^1].size();i++){
				for(int j=0;j<node[t&1].size();j++){
					f[t&1][node[t&1][j]]=min(f[t&1][node[t&1][j]],f[(t&1)^1][node[(t&1)^1][i]]+a[node[(t&1)^1][i]][node[t&1][j]]);
				}
			}
		}
		ans=min(ans,f[0][1]);
	}
	cout<<ans<<endl;
	return 0;
}


#include <ctime>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int Maxn=80;
typedef long long ll;
const ll Inf=0x3f3f3f3f3f3f3f3fll;
int a[Maxn+5][Maxn+5];
ll f[2][Maxn+5];
int n,k;
ll ans=Inf;
int vis[Maxn+5];
vector<int> node[2];
int main(){
	srand(time(0));
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			scanf("%d",&a[i][j]);
		}
	}
	int T=1000;
	ll ans=Inf;
	while(T--){
		srand(rand());
		memset(f,0x3f,sizeof f);
		node[0].clear();
		node[1].clear();
		for(int i=2;i<=n;i++){
			vis[i]=rand()&1;
			node[vis[i]].push_back(i);
		}
		node[0].push_back(1);
		f[0][1]=0;
		for(int t=1;t<=k;t++){
			memset(f[t&1],0x3f,sizeof f[t&1]);
			for(int i=0;i<node[(t&1)^1].size();i++){
				for(int j=0;j<node[t&1].size();j++){
					f[t&1][node[t&1][j]]=min(f[t&1][node[t&1][j]],f[(t&1)^1][node[(t&1)^1][i]]+a[node[(t&1)^1][i]][node[t&1][j]]);
				}
			}
		}
		ans=min(ans,f[0][1]);
	}
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int Maxn=80;
typedef long long ll;
const ll Inf=0x3f3f3f3f3f3f3f3fll;
struct Node{
	int to,val;
	friend bool operator <(Node p,Node q){
		return p.val<q.val;
	}
};
Node a[Maxn+5][Maxn+5];
ll f[Maxn+5][Maxn+5];
int n,k;
ll ans=Inf;
int vis[Maxn+5];
void dfs(int u,int find,ll now_ans){
	if(now_ans+f[u][1]>=ans){
		return;
	}
	if(find>k){
		if(u==1){
			ans=now_ans;
		}
		return;
	}
	int last=vis[u];
	vis[u]=find;
	for(int i=1;i<=n;i++){
		if(a[u][i].to==u){
			continue;
		}
		if(vis[a[u][i].to]>0&&((vis[a[u][i].to]&1)==(find&1))){
			continue;
		}
		dfs(a[u][i].to,find+1,now_ans+a[u][i].val);
	}
	vis[u]=last;
}
int main(){
	memset(f,0x3f,sizeof f);
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			scanf("%d",&a[i][j].val);
			a[i][j].to=j;
			f[i][j]=a[i][j].val;
		}
		sort(a[i]+1,a[i]+1+n);
	}
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
			}
		}
	}
	dfs(1,1,0);
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int read() {
	int x = 0 ;
	char c = getchar() ;
	while(c < 48) c = getchar() ;
	while(c > 47) x = x * 10 + (c - 48) , c = getchar() ;
	return x ;
}

int n, k;
const int maxn = 88 ;
int dis[maxn][maxn] ;
int dp[11][maxn] ;

int main() {
#ifdef Mizp
    freopen("in.txt","r",stdin);
#endif
    mt19937_64 gen(time(0));
	n = read() , k = read() ;
	for(int i = 1 ; i <= n ; i ++)
		for(int j = 1 ; j <= n ; j ++)
			dis[i][j] = read() ;

	int times = 5000 ;
	std :: vector < int > col(n + 1 , 0);
	int ans = 1e9 ;
	while(times --) {
		for(int i = 1 ; i <= n ; i ++)
			col[i] = gen() & 1 ;
		memset(dp , 0x3f , sizeof(dp)) ;
		dp[0][1] = 0;
		for(int kk = 0 ; kk < k ; kk ++)
			for(int i = 1 ; i <= n ; i ++)
				for(int j = 1 ; j <= n ; j ++)
					if(col[i] ^ col[j]) dp[kk + 1][j] = std :: min(dp[kk + 1][j] , dp[kk][i] + dis[i][j]) ;
		ans = std :: min(ans , dp[k][1]) ;
	}
	printf("%d" , ans) ;
	return 0 ;
}


#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int N = 85;
int T = 1e4, n, k, e[N][N];
int Ans = 1e9 + 7, c[N];
int dp[N][12];
void chkmn(int &a, int b){ if(a > b) a = b; }
void work(){
	for(int i = 1; i <= n; i++)
	c[i] = rand() & 1;
	memset(dp, 0x3f, sizeof(dp));
	dp[1][0] = 0;
	for(int d = 1; d <= k; d++)
	for(int i = 1; i <= n; i++)
	if(dp[i][d - 1] <= 1e9)
	for(int j = 1; j <= n; j++)
	if(c[i] ^ c[j])
	chkmn(dp[j][d], dp[i][d - 1] + e[i][j]);
	Ans = min(Ans, dp[1][k]);
}
int main(){
	#ifdef FSYo
	freopen("1.in", "r", stdin);
	#endif
	srand(time(NULL));
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
	for(int j = 1; j <= n; j++)
	scanf("%d", &e[i][j]);
	while(T--) work();
	cout << Ans;
	return 0;
}


#include <bits/stdc++.h>

inline int read() {
    char c, _c; int x; for (c = _c = getchar(); !isdigit(c); c = getchar()) { _c = c; }
    for (x = 0; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; } return _c == '-' ? -x : x;
}

const int N = 1e2 + 5;

int n, k, ans, col[N], e[N][N], f[N][N];
std::vector<int> a[2];

int main() {
    n = read(); k = read();
    for (int u = 0; u < n; u++) {
        for (int v = 0; v < n; v++) {
            e[u][v] = read();
        }
    }
    for (int i = 0; i < 233; i++) { rand(); }
    memset(f, 60, sizeof(f)); f[0][0] = 0; ans = 1e9 + 5;
    for (int _ = 0; _ < 5000; _++) {
        a[0].clear(); a[1].clear();
        for (int u = 0; u < n; u++) {
            col[u] = rand() & 1;
            a[col[u]].push_back(u);
        }
        for (int i = 1; i <= k; i++) {
            for (auto u : a[0]) {
                f[i][u] = 1e9 + 5;
                for (auto v : a[1]) {
                    f[i][u] = std::min(f[i][u], f[i - 1][v] + e[v][u]);
                }
            }
            for (auto u : a[1]) {
                f[i][u] = 1e9 + 5;
                for (auto v : a[0]) {
                    f[i][u] = std::min(f[i][u], f[i - 1][v] + e[v][u]);
                }
            }
        }
        ans = std::min(ans, f[k][0]);
    }
    printf("%d\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int sz=100, inf=1e9+10;
int n, k, an=inf;
vector <int> sp;
pair <int, int> be[sz][sz][sz];
bool us[sz];
void dfs()
{
    if(sp.size()<k and sp.size()+1<n)
    {
        for(int a=sp.back()+1; a<n; a++)
        {
            sp.push_back(a), us[a]=1;
            dfs();
            sp.pop_back(), us[a]=0;
        }
    }
    int m=sp.size();
    int sm[m][m];
    for(int a=0; a<m; a++)
    {
        for(int b=0; b<m; b++)
        {
            for(int c=0; ; c++)
            {
                if(!us[be[sp[a]][sp[b]][c].second])
                {
                    sm[a][b]=be[sp[a]][sp[b]][c].first;
                    break;
                }
            }
        }
    }
    int dp[k+1][m];
    for(int a=0; a<=k; a++) for(int b=0; b<m; b++) dp[a][b]=inf;
    dp[0][0]=0;
    for(int a=0; a<k; a++)
    {
        for(int b=0; b<m; b++)
        {
            for(int c=0; c<m; c++) dp[a+1][c]=min(dp[a+1][c], dp[a][b]+sm[b][c]);
        }
    }
    an=min(an, dp[k][0]);
}
main()
{
	//freopen("input.txt", "r", stdin);
    cin>>n>>k;
    k/=2;
    int sm[n][n];
    for(int a=0; a<n; a++)
    {
        for(int b=0; b<n; b++) scanf("%d", &sm[a][b]);
    }
    for(int a=0; a<n; a++) sm[a][a]=inf;
    for(int a=0; a<n; a++)
    {
        for(int b=0; b<n; b++)
        {
            for(int c=0; c<n; c++) be[a][b][c]={sm[a][c]+sm[c][b], c};
            sort(be[a][b], be[a][b]+n);
        }
    }
    sp.push_back(0), us[0]=1;
    dfs();
    cout<<an;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define Rep(i,a,n) for (int i=a;i<=n;i++)
#define Per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
ll d[100][100];
vector<pair<ll,int> > v[100][100];
bool f[100];
signed main(){
    int n,k;scanf("%d%d",&n,&k);
    Rep(i,1,n){
        Rep(j,1,n){
            scanf("%lld",&d[i][j]);
        }
    }
    Rep(i,1,n){
        Rep(j,1,n){
            Rep(k,1,n){
                if(k!=i&&k!=j){
                    v[i][j].pb(mp(d[i][k]+d[k][j],k));
                }
            }
            sort(all(v[i][j]));
        }
    }
    if(k==2){
        ll ans=v[1][1][0].first;
        cout<<ans<<endl;
        return 0;
    }
    if(k==4){
        ll ans=1e18;
        for(int i1=1;i1<=1;i1++)
        for(int i3=1;i3<=n;i3++)
        for(int i5=1;i5<=1;i5++){
            f[i1]=f[i3]=f[i5]=1;
            int id1=0,id2=0;
            while(f[v[i1][i3][id1].se]) id1++;
            while(f[v[i3][i5][id2].se]) id2++;
            ans=min(ans,v[i1][i3][id1].fi+v[i3][i5][id2].fi);
            f[i1]=f[i3]=f[i5]=0;
        }
        cout<<ans<<endl;return 0;
    }
    if(k==6){
        ll ans=1e18;
        for(int i1=1;i1<=1;i1++)
        for(int i3=1;i3<=n;i3++)
        for(int i5=1;i5<=n;i5++)
        for(int i7=1;i7<=1;i7++)
        {
            f[i1]=f[i3]=f[i5]=1;
            int id1=0,id2=0,id3=0;
            while(f[v[i1][i3][id1].se]) id1++;
            while(f[v[i3][i5][id2].se]) id2++;
            while(f[v[i5][i7][id3].se]) id3++;
            ans=min(ans,v[i1][i3][id1].fi+v[i3][i5][id2].fi+v[i5][i7][id3].fi);
             f[i1]=f[i3]=f[i5]=0;
        }
        cout<<ans<<endl;return 0;
    }
    if(k==8){
        ll ans=1e18;
        for(int i1=1;i1<=1;i1++)
        for(int i3=1;i3<=n;i3++)
        for(int i5=1;i5<=n;i5++)
        for(int i7=1;i7<=n;i7++)
        for(int i9=1;i9<=1;i9++)
        {
             f[i1]=f[i3]=f[i5]=f[i7]=1;
            int id1=0,id2=0,id3=0,id4=0;
            while(f[v[i1][i3][id1].se]) id1++;
            while(f[v[i3][i5][id2].se]) id2++;
            while(f[v[i5][i7][id3].se]) id3++;
            while(f[v[i5][i7][id4].se]) id4++;
            ans=min(ans,v[i1][i3][id1].fi+v[i3][i5][id2].fi+v[i5][i7][id3].fi+v[i7][i9][id4].fi);
            f[i1]=f[i3]=f[i5]=f[i7]=0;
        }
        cout<<ans<<endl;return 0;
    }
    if(k==10){
        ll ans=1e18;
        for(int i1=1;i1<=1;i1++)
        for(int i3=1;i3<=n;i3++)
        for(int i5=1;i5<=n;i5++)
        for(int i7=1;i7<=n;i7++)
        for(int i9=1;i9<=n;i9++)
        for(int i11=1;i11<=1;i11++)
        {
            f[i1]=f[i3]=f[i5]=f[i7]=f[i9]=1;
            int id1=0,id2=0,id3=0,id4=0,id5=0;
            while(f[v[i1][i3][id1].se]) id1++;
            while(f[v[i3][i5][id2].se]) id2++;
            while(f[v[i5][i7][id3].se]) id3++;
            while(f[v[i5][i7][id4].se]) id4++;
            while(f[v[i5][i7][id5].se]) id5++;
            ans=min(ans,v[i1][i3][id1].fi+v[i3][i5][id2].fi+v[i5][i7][id3].fi+v[i7][i9][id4].fi+v[i9][i11][id5].fi);
            f[i1]=f[i3]=f[i5]=f[i7]=f[i9]=0;
        }
        cout<<ans<<endl;return 0;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define Rep(i,a,n) for (int i=a;i<=n;i++)
#define Per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
ll d[100][100];
vector<pair<ll,int> > v[100][100];
bool f[100];
signed main(){
    int n,k;scanf("%d%d",&n,&k);
    Rep(i,1,n){
        Rep(j,1,n){
            scanf("%lld",&d[i][j]);
        }
    }
    Rep(i,1,n){
        Rep(j,1,n){
            Rep(k,1,n){
                if(k!=i&&k!=j){
                    v[i][j].pb(mp(d[i][k]+d[k][j],k));
                }
            }
            sort(all(v[i][j]));
        }
    }
    if(k==2){
        ll ans=v[1][1][0].first;
        cout<<ans<<endl;
        return 0;
    }
    if(k==4){
        ll ans=1e18;
        for(int i1=1;i1<=1;i1++)
        for(int i3=1;i3<=n;i3++)
        for(int i5=1;i5<=1;i5++){
            f[i1]=f[i3]=1;
            int id1=0,id2=0;
            while(f[v[i1][i3][id1].se]) id1++;
            while(f[v[i3][i5][id2].se]) id2++;
            ans=min(ans,v[i1][i3][id1].fi+v[i3][i5][id2].fi);
            f[i1]=f[i3]=0;
        }
        cout<<ans<<endl;return 0;
    }
    if(k==6){
        ll ans=1e18;
        for(int i1=1;i1<=1;i1++)
        for(int i3=1;i3<=n;i3++)
        for(int i5=1;i5<=n;i5++)
        for(int i7=1;i7<=1;i7++)
        {
            f[i1]=f[i3]=f[i5]=1;
            int id1=0,id2=0,id3=0;
            while(f[v[i1][i3][id1].se]) id1++;
            while(f[v[i3][i5][id2].se]) id2++;
            while(f[v[i5][i7][id3].se]) id3++;
            ans=min(ans,v[i1][i3][id1].fi+v[i3][i5][id2].fi+v[i5][i7][id3].fi);
             f[i1]=f[i3]=f[i5]=0;
        }
        cout<<ans<<endl;return 0;
    }
    if(k==8){
        ll ans=1e18;
        for(int i1=1;i1<=1;i1++)
        for(int i3=1;i3<=n;i3++)
        for(int i5=1;i5<=n;i5++)
        for(int i7=1;i7<=n;i7++)
        for(int i9=1;i9<=1;i9++)
        {
             f[i1]=f[i3]=f[i5]=f[i7]=1;
            int id1=0,id2=0,id3=0,id4=0;
            while(f[v[i1][i3][id1].se]) id1++;
            while(f[v[i3][i5][id2].se]) id2++;
            while(f[v[i5][i7][id3].se]) id3++;
            while(f[v[i7][i9][id4].se]) id4++;
            ans=min(ans,v[i1][i3][id1].fi+v[i3][i5][id2].fi+v[i5][i7][id3].fi+v[i7][i9][id4].fi);
            f[i1]=f[i3]=f[i5]=f[i7]=0;
        }
        cout<<ans<<endl;return 0;
    }
    if(k==10){
        ll ans=1e18;
        for(int i1=1;i1<=1;i1++)
        for(int i3=1;i3<=n;i3++)
        for(int i5=1;i5<=n;i5++)
        for(int i7=1;i7<=n;i7++)
        for(int i9=1;i9<=n;i9++)
        for(int i11=1;i11<=1;i11++)
        {
            f[i1]=f[i3]=f[i5]=f[i7]=f[i9]=1;
            int id1=0,id2=0,id3=0,id4=0,id5=0;
            while(f[v[i1][i3][id1].se]) id1++;
            while(f[v[i3][i5][id2].se]) id2++;
            while(f[v[i5][i7][id3].se]) id3++;
            while(f[v[i7][i9][id4].se]) id4++;
            while(f[v[i9][i11][id5].se]) id5++;
            ans=min(ans,v[i1][i3][id1].fi+v[i3][i5][id2].fi+v[i5][i7][id3].fi+v[i7][i9][id4].fi+v[i9][i11][id5].fi);
            f[i1]=f[i3]=f[i5]=f[i7]=f[i9]=0;
        }
        cout<<ans<<endl;return 0;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define Rep(i,a,n) for (int i=a;i<=n;i++)
#define Per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
ll d[100][100];
vector<pair<ll,int> > v[100][100];
signed main(){
    int n,k;scanf("%d%d",&n,&k);
    Rep(i,1,n){
        Rep(j,1,n){
            scanf("%lld",&d[i][j]);

        }
    }
    Rep(i,1,n){
        Rep(j,1,n){
            Rep(k,1,n){
                if(k!=i&&k!=j){
                    v[i][j].pb(mp(d[i][k]+d[k][j],k));
                }
            }
            sort(all(v[i][j]));
        }
    }
    if(k==2){
        ll ans=v[1][1][0].first;
        cout<<ans<<endl;
        return 0;
    }
    if(k==4){
        ll ans=1e18;
        for(int i1=1;i1<=1;i1++)
        for(int i3=1;i3<=n;i3++)
        for(int i5=1;i5<=1;i5++){
            unordered_set<int> st;st.insert(i1);st.insert(i3);st.insert(i5);
            int id1=0,id2=0;
            while(st.find(v[i1][i3][id1].se)!=st.end()) id1++;
            while(st.find(v[i3][i5][id2].se)!=st.end()) id2++;
            ans=min(ans,v[i1][i3][id1].fi+v[i3][i5][id2].fi);
        }
        cout<<ans<<endl;return 0;
    }
    if(k==6){
        ll ans=1e18;
        for(int i1=1;i1<=1;i1++)
        for(int i3=1;i3<=n;i3++)
        for(int i5=1;i5<=n;i5++)
        for(int i7=1;i7<=1;i7++)
        {
            unordered_set<int> st;st.insert(i1);st.insert(i3);st.insert(i5);
            int id1=0,id2=0,id3=0;
            while(st.find(v[i1][i3][id1].se)!=st.end()) id1++;
            while(st.find(v[i3][i5][id2].se)!=st.end()) id2++;
            while(st.find(v[i5][i7][id3].se)!=st.end()) id3++;
            ans=min(ans,v[i1][i3][id1].fi+v[i3][i5][id2].fi+v[i5][i7][id3].fi);
        }
        cout<<ans<<endl;return 0;
    }
    if(k==8){
        ll ans=1e18;
        for(int i1=1;i1<=1;i1++)
        for(int i3=1;i3<=n;i3++)
        for(int i5=1;i5<=n;i5++)
        for(int i7=1;i7<=n;i7++)
        for(int i9=1;i9<=1;i9++)
        {
            unordered_set<int> st;st.insert(i1);st.insert(i3);st.insert(i5);st.insert(i7);
            int id1=0,id2=0,id3=0,id4=0;
            while(st.find(v[i1][i3][id1].se)!=st.end()) id1++;
            while(st.find(v[i3][i5][id2].se)!=st.end()) id2++;
            while(st.find(v[i5][i7][id3].se)!=st.end()) id3++;
            while(st.find(v[i7][i9][id4].se)!=st.end()) id4++;
            ans=min(ans,v[i1][i3][id1].fi+v[i3][i5][id2].fi+v[i5][i7][id3].fi+v[i7][i9][id4].fi);
        }
        cout<<ans<<endl;return 0;
    }
    if(k==10){
        ll ans=1e18;
        for(int i1=1;i1<=1;i1++)
        for(int i3=1;i3<=n;i3++)
        for(int i5=1;i5<=n;i5++)
        for(int i7=1;i7<=n;i7++)
        for(int i9=1;i9<=n;i9++)
        for(int i11=1;i11<=1;i11++)
        {
            unordered_set<int> st;st.insert(i1);st.insert(i3);st.insert(i5);st.insert(i7);st.insert(i9);
            int id1=0,id2=0,id3=0,id4=0,id5=0;
            while(st.find(v[i1][i3][id1].se)!=st.end()) id1++;
            while(st.find(v[i3][i5][id2].se)!=st.end()) id2++;
            while(st.find(v[i5][i7][id3].se)!=st.end()) id3++;
            while(st.find(v[i7][i9][id4].se)!=st.end()) id4++;
            while(st.find(v[i9][i11][id5].se)!=st.end()) id5++;
            ans=min(ans,v[i1][i3][id1].fi+v[i3][i5][id2].fi+v[i5][i7][id3].fi+v[i7][i9][id4].fi+v[i9][i11][id5].fi);
        }
        cout<<ans<<endl;return 0;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
//#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define SZ(x) (int)(x.size())
#define mem(x, y) memset(x, y, sizeof(x))
#define what_is(x) cerr <<  "Line " << __LINE__ << ": " << #x << " is " << (x) << endl;
#define suf_zero(x) __builtin_ffs(x)
#define pre_zero(x) __builtin_clz(x)
#define num_one(x) __builtin_popcount(x)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mp make_pair
#define eb push_back
#define INFI 2000000009
#define INFLL (ll)1e18+7
#define fi first
#define se second
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1
void err(istream_iterator<string> it) {cerr<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " , ";
    err(++it, args...);
}
const double pi = acos(-1.0);
//const double eps = 1e-10;
const int mod = 998244353;
#define mul(a, b) 1LL * (a) * (b) % mod
#define add(a, b) (a + b >= mod ? a + b - mod : a + b)
#define sub(a, b) (a - b <  0 ? a - b + mod : a - b)
//#define RG register
namespace fastIO{
    #define BUF_SIZE 20000000
//     fread -> read
    bool IOerror = 0;
    static char obuf[BUF_SIZE], *OUT=obuf;
    inline char nc(){
        static char buf[BUF_SIZE], *p1 = buf+BUF_SIZE,
         *pend = buf+BUF_SIZE;
         if(p1==pend){
             p1 = buf;
             pend = buf+fread(buf, 1, BUF_SIZE, stdin);
             if(pend==p1){
                 IOerror = 1;
                 return -1;
             }
         }
         return *p1++;
    }
    inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}

    template<typename T>
    inline int read(T &x){
        char ch;
        while(blank(ch=nc()));
        if(IOerror)return -1;
        int ok = 0;
        if(ch=='-') ok=1, ch=nc();
        for(x=ch-'0';(ch=nc())>='0'&&ch<='9';x=x*10+ch-'0');
        if(ok) x=-x;
        return 1;
    }
    template<typename T>
    void print(const T& x) {
        if(x > 9) print(x / 10);
        *OUT++= x % 10 + '0';
    }
    void print(){fwrite(obuf, OUT-obuf, 1, stdout);}
    #undef BUF_SIZE
}
using namespace fastIO;
///////////// BOUND /////////////////
ll qp(ll b, ll n){ll r=1;if(n<0)n+=mod-1;b%=mod;for(;n;n>>=1,b=b*b%mod)if(n&1)r=r*b%mod;return r;}
//#define inv(x) (qp((x), mod-2))
/////////////// Macro ///////////////
const int maxn = 2e5+7;
int d[81][81];
int n, k, ans = INFI;
int pos[81];
void dfs(int now, int pre, int cnt)
{
    if(cnt>=ans) return;
    if(now==k)
    {
        ans = min(ans, cnt+d[pre][1]);
        return ;
    }
    if(now%2!=1)
    {
        pos[now] = 1;
        dfs(now+1, 1, cnt+d[pre][1]);
    }
    for(int i=2;i<=n;++i)
    {
        if(i==pre) continue;
        int ok = 1;
        for(int j=3;j<now;j+=2) if(pos[now-j]==i) ok = 0;
        if(ok==0)continue;
        pos[now] = i;
        dfs(now+1, i, cnt+d[pre][i]);
    }
}

int main()
{
    scanf("%d%d", &n, &k);
    for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) scanf("%d", &d[i][j]);
    dfs(1, 1, 0);
    cout << ans << endl;
}

/*
0 1
1 3
2 5
3 6
4 5
5 3
6 1
*/


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=1e7+1;

int n;
int dis[81][81];
ll dp[81][10];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
            cin>>dis[i][j];
    }
    ll ans=0x3f3f3f3f;
    srand(time(0));
    int num1[100],num2[100],op1=0,op2=0;
    num1[1]=0;
    for(int i=1; i<7000; i++)
    {
        memset(dp,0x3f3f3f3f,sizeof(dp));
        op1=1,op2=0;
        for(int j=1;j<n;j++)
        {
            int x=rand()%2;
            if(x==1) num1[++op1]=j;
            else num2[++op2]=j;
        }
        for(int j=1; j<=op2; j++)
        {
            dp[1][num2[j]]=dis[0][num2[j]];
        }
        for(int j=1; j<k; j++)
        {
            if(j%2)
                for(int l=1; l<=op2; l++)
                    for(int r=1; r<=op1; r++)
                        dp[j+1][num1[r]]=min(dp[j+1][num1[r]],dp[j][num2[l]]+dis[num2[l]][num1[r]]);
            else
                for(int l=1; l<=op1; l++)
                    for(int r=1; r<=op2; r++)
                        dp[j+1][num2[r]]=min(dp[j+1][num2[r]],dp[j][num1[l]]+dis[num1[l]][num2[r]]);
        }
        ans=min(ans,dp[k][1]);
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=1e7+1;

int n;
int dis[81][81];
ll dp[81][10];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
            cin>>dis[i][j];
    }
    ll ans=0x3f3f3f3f;
    srand(time(0));
    int num1[100],num2[100],op1=0,op2=0;
    num1[1]=0;
    for(int i=1; i<5000; i++)
    {
        memset(dp,0x3f3f3f3f,sizeof(dp));
        op1=1,op2=0;
        for(int j=1;j<n;j++)
        {
            int x=rand()%2;
            if(x==1) num1[++op1]=j;
            else num2[++op2]=j;
        }
        for(int j=1; j<=op2; j++)
        {
            dp[1][num2[j]]=dis[0][num2[j]];
        }
        for(int j=1; j<k; j++)
        {
            if(j%2)
                for(int l=1; l<=op2; l++)
                    for(int r=1; r<=op1; r++)
                        dp[j+1][num1[r]]=min(dp[j+1][num1[r]],dp[j][num2[l]]+dis[num2[l]][num1[r]]);
            else
                for(int l=1; l<=op1; l++)
                    for(int r=1; r<=op2; r++)
                        dp[j+1][num2[r]]=min(dp[j+1][num2[r]],dp[j][num1[l]]+dis[num1[l]][num2[r]]);
        }
        ans=min(ans,dp[k][0]);
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=1e7+1;

int n;
int dis[81][81];
ll dp[81][11];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
            cin>>dis[i][j];
    }
    ll ans=0x3f3f3f3f;
    srand(time(0));
    int num1[100],num2[100],op1=0,op2=0;
    num1[1]=0;
    for(int i=1; i<5000; i++)
    {
        memset(dp,0x3f3f3f3f,sizeof(dp));
        op1=1,op2=0;
        for(int j=1;j<n;j++)
        {
            int x=rand()%2;
            if(x==1) num1[++op1]=j;
            else num2[++op2]=j;
        }
        for(int j=1; j<=op2; j++)
        {
            dp[1][num2[j]]=dis[0][num2[j]];
        }
        for(int j=1; j<k; j++)
        {
            if(j%2)
                for(int l=1; l<=op2; l++)
                    for(int r=1; r<=op1; r++)
                        dp[j+1][num1[r]]=min(dp[j+1][num1[r]],dp[j][num2[l]]+dis[num2[l]][num1[r]]);
            else
                for(int l=1; l<=op1; l++)
                    for(int r=1; r<=op2; r++)
                        dp[j+1][num2[r]]=min(dp[j+1][num2[r]],dp[j][num1[l]]+dis[num1[l]][num2[r]]);
        }
        ans=min(ans,dp[k][0]);
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=1e7+1;

int n;
int dis[81][81];
ll dp[81][81];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
            cin>>dis[i][j];
    }
    ll ans=0x3f3f3f3f;
    srand(time(0));
    int num1[100],num2[100],op1=0,op2=0;
    num1[1]=0;
    for(int i=1; i<5000; i++)
    {
        memset(dp,0x3f3f3f3f,sizeof(dp));
        op1=1,op2=0;
        for(int j=1;j<n;j++)
        {
            int x=rand()%2;
            if(x==1) num1[++op1]=j;
            else num2[++op2]=j;
        }
        for(int j=1; j<=op2; j++)
        {
            dp[1][num2[j]]=dis[0][num2[j]];
        }
        for(int j=1; j<k; j++)
        {
            if(j%2)
                for(int l=1; l<=op2; l++)
                    for(int r=1; r<=op1; r++)
                        dp[j+1][num1[r]]=min(dp[j+1][num1[r]],dp[j][num2[l]]+dis[num2[l]][num1[r]]);
            else
                for(int l=1; l<=op1; l++)
                    for(int r=1; r<=op2; r++)
                        dp[j+1][num2[r]]=min(dp[j+1][num2[r]],dp[j][num1[l]]+dis[num1[l]][num2[r]]);
        }
        ans=min(ans,dp[k][0]);
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=1e7+1;

int n;
int dis[81][81];
ll dp[81][10];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
            cin>>dis[i][j];
    }
    ll ans=0x3f3f3f3f;
    srand(time(115));
    int num1[100],num2[100],op1=0,op2=0;
    num1[1]=0;
    for(int i=1; i<5000; i++)
    {
        memset(dp,0x3f3f3f3f,sizeof(dp));
        op1=1,op2=0;
        for(int j=1;j<n;j++)
        {
            int x=rand()%2;
            if(x==1) num1[++op1]=j;
            else num2[++op2]=j;
        }
        for(int j=1; j<=op2; j++)
        {
            dp[1][num2[j]]=dis[0][num2[j]];
        }
        for(int j=1; j<k; j++)
        {
            if(j%2)
                for(int l=1; l<=op2; l++)
                    for(int r=1; r<=op1; r++)
                        dp[j+1][num1[r]]=min(dp[j+1][num1[r]],dp[j][num2[l]]+dis[num2[l]][num1[r]]);
            else
                for(int l=1; l<=op1; l++)
                    for(int r=1; r<=op2; r++)
                        dp[j+1][num2[r]]=min(dp[j+1][num2[r]],dp[j][num1[l]]+dis[num1[l]][num2[r]]);
        }
        ans=min(ans,dp[k][0]);
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define fr first
#define sc second

const int INF = 1000000000;

int n,k;
int w[82][82];

P cost[82][82][82];
void init_cost(){
	for(int i = 0 ; i < n ; i ++){
		for(int j = 0 ; j < n ; j ++){
			int cnt = 0;
			for(int k = 0 ; k < n ; k ++){
				if(k == i || k == j)continue;
				cost[i][j][cnt++] = P(w[i][k]+w[k][j],k);
			}
			sort(cost[i][j],cost[i][j]+cnt);
		}
	}
}

int x[5];
int ret = INF;
bool used[82];
int c[5][5];
int dp[6][5];
void dfs(int t){
	for(int i = 0 ; i < k/2 ; ++i){
		for(int j = 0 ; j < k/2 ; ++j){
			for(int s = 0 ; ; ++s){
				if(!used[cost[i][j][s].sc]){
					c[i][j] = cost[i][j][s].fr;
					break;
				}
			}
		}
	}
	for(int i = 0 ; i <= k/2 ; ++i){
		for(int j = 0 ; j < t ; ++j){
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;
	for(int i = 0 ; i < k/2 ; ++i){
		for(int j = 0 ; j < t ; ++j){
			for(int nex = 0 ; nex < t ; ++nex){
				if(dp[i+1][nex] > dp[i][j]+c[j][nex]){
					dp[i+1][nex] = dp[i][j]+c[j][nex];
				}
			}
		}
	}
	ret = min( ret , dp[k/2][0] );
	if(t == k/2 || t+1 == n)return;
	for(int i = x[t-1]+1 ; i < n ; i ++){
		x[t] = i;
		used[i] = true;
		dfs(t+1);
		used[i] = false;
	}
}

int main(){
	scanf("%d%d",&n,&k);
	for(int i = 0 ; i < n ; i ++){
		for(int j = 0 ; j < n ; j ++){
			scanf("%d",&w[i][j]);
		}
	}
	init_cost();
	x[0] = 0;
	for(int i = 0 ; i < 82 ; i ++){
		used[i] = false;
	}
	used[0] = true;
	dfs(1);
	cout << ret << endl;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define fr first
#define sc second

const int INF = 1000000000;

int n,k;
int w[82][82];

P cost[82][82][82];
void init_cost(){
	for(int i = 0 ; i < n ; i ++){
		for(int j = 0 ; j < n ; j ++){
			int cnt = 0;
			for(int k = 0 ; k < n ; k ++){
				if(k == i || k == j)continue;
				cost[i][j][cnt++] = P(w[i][k]+w[k][j],k);
			}
			sort(cost[i][j],cost[i][j]+cnt);
		}
	}
}

int x[5];
int ret = INF;
bool used[82];
int c[5][5];
int dp[6][5];
void dfs(int t){
	for(int i = 0 ; i < t ; ++i){
		for(int j = 0 ; j < t ; ++j){
			for(int s = 0 ; ; ++s){
				if(!used[cost[x[i]][x[j]][s].sc]){
					c[i][j] = cost[x[i]][x[j]][s].fr;
					break;
				}
			}
		}
	}
	for(int i = 0 ; i <= k/2 ; ++i){
		for(int j = 0 ; j < t ; ++j){
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;
	for(int i = 0 ; i < k/2 ; ++i){
		for(int j = 0 ; j < t ; ++j){
			for(int nex = 0 ; nex < t ; ++nex){
				if(dp[i+1][nex] > dp[i][j]+c[j][nex]){
					dp[i+1][nex] = dp[i][j]+c[j][nex];
				}
			}
		}
	}
	ret = min( ret , dp[k/2][0] );
	if(t == k/2 || t+1 == n)return;
	for(int i = x[t-1]+1 ; i < n ; i ++){
		x[t] = i;
		used[i] = true;
		dfs(t+1);
		used[i] = false;
	}
}

int main(){
	scanf("%d%d",&n,&k);
	for(int i = 0 ; i < n ; i ++){
		for(int j = 0 ; j < n ; j ++){
			scanf("%d",&w[i][j]);
		}
	}
	init_cost();
	x[0] = 0;
	for(int i = 0 ; i < 82 ; i ++){
		used[i] = false;
	}
	used[0] = true;
	dfs(1);
	cout << ret << endl;
}


#include <bits/stdc++.h>

template <class T>
inline void read(T &res)
{
	res = 0; bool bo = 0; char c;
	while (((c = getchar()) < '0' || c > '9') && c != '-');
	if (c == '-') bo = 1; else res = c - 48;
	while ((c = getchar()) >= '0' && c <= '9')
		res = (res << 3) + (res << 1) + (c - 48);
	if (bo) res = ~res + 1;
}

const int N = 85, INF = 0x3f3f3f3f;

int n, k, a[N][N], tot = 1, arr[N], ans = INF, f[N][N], d[N][N];
bool vis[N];

struct elem
{
	int v, d;
} eg[N][N][N];

inline bool comp(elem a, elem b)
{
	return a.d < b.d;
}

int calcd(int u, int v)
{
	for (int i = 1; i <= n - 1 - (u != v); i++)
		if (!vis[eg[u][v][i].v]) return eg[u][v][i].d;
	return INF;
}

void check()
{
	for (int i = 1; i <= tot; i++)
		for (int j = 1; j <= tot; j++)
			d[i][j] = calcd(arr[i], arr[j]);
	for (int i = 0; i <= k; i++)
		for (int j = 1; j <= tot; j++)
			f[i][j] = INF;
	f[0][1] = 0;
	for (int i = 1; i <= k; i++)
		for (int u = 1; u <= tot; u++)
			for (int v = 1; v <= tot; v++)
				f[i][u] = std::min(f[i][u], f[i - 1][v] + d[v][u]);
	ans = std::min(ans, f[k][1]);
}

void dfs(int dep)
{
	if (dep > n) return check();
	if (tot < k) arr[++tot] = dep, vis[dep] = 1, dfs(dep + 1), vis[dep] = 0;
	dfs(dep + 1);
}

int main()
{
	vis[1] = 1; arr[1] = 1;
	read(n); read(k); k >>= 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			read(a[i][j]);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
		{
			int tot = 0;
			for (int k = 1; k <= n; k++) if (i != k && j != k)
				eg[i][j][++tot] = (elem) {k, a[i][k] + a[k][j]};
			std::sort(eg[i][j] + 1, eg[i][j] + tot + 1, comp);
		}
	dfs(2);
	return std::cout << ans << std::endl, 0;
}


#include <bits/stdc++.h>

template <class T>
inline void read(T &res)
{
	res = 0; bool bo = 0; char c;
	while (((c = getchar()) < '0' || c > '9') && c != '-');
	if (c == '-') bo = 1; else res = c - 48;
	while ((c = getchar()) >= '0' && c <= '9')
		res = (res << 3) + (res << 1) + (c - 48);
	if (bo) res = ~res + 1;
}

const int N = 85, INF = 0x3f3f3f3f;

int n, k, a[N][N], tot = 1, arr[N], ans = INF, f[N][N], d[N][N];
bool vis[N];

struct elem
{
	int v, d;
} eg[N][N][N];

inline bool comp(elem a, elem b)
{
	return a.d < b.d;
}

int calcd(int u, int v)
{
	for (int i = 1; i <= n - 1 - (u != v); i++)
		if (!vis[eg[u][v][i].v]) return eg[u][v][i].d;
	return INF;
}

void check()
{
	for (int i = 1; i <= tot; i++)
		for (int j = 1; j <= tot; j++)
			d[i][j] = calcd(arr[i], arr[j]);
	for (int i = 0; i <= k; i++)
		for (int j = 1; j <= tot; j++)
			f[i][j] = INF;
	f[0][1] = 0;
	for (int i = 1; i <= k; i++)
		for (int u = 1; u <= tot; u++)
			for (int v = 1; v <= tot; v++)
				f[i][u] = std::min(f[i][u], f[i - 1][v] + d[v][u]);
	ans = std::min(ans, f[k][1]);
}

void dfs(int dep)
{
	if (dep > n) return check();
	if (tot < k) arr[++tot] = dep, vis[dep] = 1, dfs(dep + 1), vis[dep] = 0, tot--;
	dfs(dep + 1);
}

int main()
{
	vis[1] = 1; arr[1] = 1;
	read(n); read(k); k >>= 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			read(a[i][j]);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
		{
			int tot = 0;
			for (int k = 1; k <= n; k++) if (i != k && j != k)
				eg[i][j][++tot] = (elem) {k, a[i][k] + a[k][j]};
			std::sort(eg[i][j] + 1, eg[i][j] + tot + 1, comp);
		}
	dfs(2);
	return std::cout << ans << std::endl, 0;
}


#include <bits/stdc++.h>

template <class T>
inline void read(T &res)
{
	res = 0; bool bo = 0; char c;
	while (((c = getchar()) < '0' || c > '9') && c != '-');
	if (c == '-') bo = 1; else res = c - 48;
	while ((c = getchar()) >= '0' && c <= '9')
		res = (res << 3) + (res << 1) + (c - 48);
	if (bo) res = ~res + 1;
}

const int N = 85, INF = 0x3f3f3f3f;

int n, k, a[N][N], tot = 1, arr[N], ans = INF, f[N][N], d[N][N];
bool vis[N];

struct elem
{
	int v, d;
} eg[N][N][N];

inline bool comp(elem a, elem b)
{
	return a.d < b.d;
}

int calcd(int u, int v)
{
	for (int i = 1; i <= n - 1 - (u != v); i++)
		if (!vis[eg[u][v][i].v]) return eg[u][v][i].d;
	return INF;
}

void check()
{
	for (int i = 1; i <= tot; i++)
		for (int j = 1; j <= tot; j++)
			d[i][j] = calcd(arr[i], arr[j]);
	for (int i = 0; i <= k; i++)
		for (int j = 1; j <= tot; j++)
			f[i][j] = INF;
	f[0][1] = 0;
	for (int i = 1; i <= k; i++)
		for (int u = 1; u <= tot; u++)
			for (int v = 1; v <= tot; v++)
				f[i][u] = std::min(f[i][u], f[i - 1][v] + d[v][u]);
	ans = std::min(ans, f[k][1]);
}

void dfs(int dep)
{
	if (dep > n) return check();
	if (tot < k) arr[++tot] = dep, vis[dep] = 1, dfs(dep + 1), vis[dep] = 0;
	dfs(dep + 1);
}

int main()
{
	vis[1] = 1; arr[tot = 1] = 1;
	read(n); read(k); k >>= 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			read(a[i][j]);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
		{
			int tot = 0;
			for (int k = 1; k <= n; k++) if (i != k && j != k)
				eg[i][j][++tot] = (elem) {k, a[i][k] + a[k][j]};
			std::sort(eg[i][j] + 1, eg[i][j] + tot + 1, comp);
		}
	dfs(2);
	return std::cout << ans << std::endl, 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=82,I=1e9;
bool v[N];
long long n,K,a[N][N],f[N][N][N],g[N][N][N],p,w[N],A=I,t;
priority_queue<pair<int,int> >q;
void D(int x)
{
	if(!x)
	{
		t=0;
		for(int i=0;i<K;i++)
			for(int j=1;j<=n;j++)
				if(!v[f[w[i]][w[i+1]][j]])
					t+=g[w[i]][w[i+1]][j],j=n;
		A=min(A,t);
		return;
	}
	for(int i=1;i<=n;i++)
		w[x]=i,v[i]=true,D(x-1),v[i]=false;
}
int main()
{
	cin>>n>>K;
	K/=2;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			cin>>a[i][j];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			for(int k=2;k<=n;k++)
				if(k!=i&&k!=j)
					q.push(make_pair(-a[i][k]-a[k][j],k));
			p=0;
			while(!q.empty())
				f[i][j][++p]=q.top().second,g[i][j][p]=-q.top().first,q.pop();
			for(int k=p+1;k<=n;k++)
				g[i][j][k]=I;
		}
	w[0]=w[K]=1;
	D(K-1);
	cout<<A;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=82,I=1e9;
long long v[N],n,K,a[N][N],f[N][N][N],g[N][N][N],p,w[N],A=I,t;
priority_queue<pair<int,int> >q;
void D(int x)
{
	if(!x)
	{
		t=0;
		for(int i=0;i<K;i++)
			for(int j=1;j<=n;j++)
				if(!v[f[w[i]][w[i+1]][j]])
					t+=g[w[i]][w[i+1]][j],j=n;
		A=min(A,t);
		return;
	}
	for(int i=1;i<=n;i++)
		w[x]=i,v[i]++,D(x-1),v[i]--;
}
int main()
{
	cin>>n>>K;
	K/=2;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			cin>>a[i][j];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			for(int k=2;k<=n;k++)
				if(k!=i&&k!=j)
					q.push(make_pair(-a[i][k]-a[k][j],k));
			p=0;
			while(!q.empty())
				f[i][j][++p]=q.top().second,g[i][j][p]=-q.top().first,q.pop();
			for(int k=p+1;k<=n;k++)
				g[i][j][k]=I;
		}
	w[0]=w[K]=1;
	D(K-1);
	cout<<A;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=81,I=1e9;
bool v[N];
long long n,K,a[N][N],f[N][N][N],g[N][N][N],p,w[N],A=I,t;
priority_queue<pair<int,int> >q;
void D(int x)
{
	if(!x)
	{
		t=0;
		for(int i=0;i<K;i++)
			for(int j=1;j<=n;j++)
				if(!v[f[w[i]][w[i+1]][j]])
					t+=g[w[i]][w[i+1]][j],j=n;
		A=min(A,t);
		return;
	}
	for(int i=1;i<=n;i++)
		w[x]=i,v[i]=true,D(x-1),v[i]=false;
}
int main()
{
	cin>>n>>K;
	K/=2;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			cin>>a[i][j];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			for(int k=2;k<=n;k++)
				if(k!=i&&k!=j)
					q.push(make_pair(-a[i][k]-a[k][j],k));
			p=1;
			while(!q.empty())
				f[i][j][p]=q.top().second,g[i][j][p++]=-q.top().first,q.pop();
			for(int k=p+1;k<=n;k++)
				g[i][j][k]=I;
		}
	w[0]=w[K]=1;
	D(K-1);
	cout<<A;
	return 0;
}


//#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <sstream>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<ctime>
#include<cmath>
#include<map>
#include<unordered_map>
#include<stack>
#include<random>
#include<queue>
#include<list>
#include<math.h>
#include<bitset>
#include<fstream>
using namespace std;
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define ii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int> >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define nu 100001
#define mul(x,y) ((ll)(x)*(y))%mod
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < int(n); i++)
const ll INF=9223372036854775807;
const ll mod=1e9+7;
ll  max3(ll  a,ll  b, ll  c)
{
    return max(c,max(a,b));
}
ll min3(ll  a,ll  b,ll  c)
{
    return min(a,min(b,c));
}
ll  power(ll  x,ll  y,ll mod1)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%mod1;
        y = y>>1;
        x = (x*x)%mod1;
    }
    return res;
}
ll  power1(ll  x,ll  y)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}
ll logg(ll  a)
{
    ll  x=0;
    while(a>1)
    {
        x++;
        a/=2;
    }
    return x;
}
ll  gcd(ll  a,ll   b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll abso(ll x)
{
    if(x<0)
    {
        return -x;
    }
    return x;
}
ll ceiling (ll  a,ll  b)
{
    if(a%b==0)
    {
        return a/b;
    }
    else
    {
        return a/b+1;
    }
}
ll modinv(ll x,ll p)
{
    return power(x,p-2,p);
}
struct point
{
    ll x;ll y;
};
ll cross(point a,point b)
{
    return a.x*b.y-b.x*a.y;
}
bool ccw1(point p1,point p2)
{
    /* point n1;n1.x=p1.x-p0.x;n1.y=p1.y-p0.y;
     point n2;n2.x=p2.x-p0.x;n2.y=p2.y-p0.y;*/
    if(cross(p1,p2)>0)
    {
        return true;
    }
    else
    {
        return false;
        //No need to worry about cross=0 case in this question;
    }
}
bool comp(point p1,point p2)
{
    if(p1.x<p2.x)
    {
        return true;
    }
    else
    {
        if(p1.x>p2.x)
        {
            return false;
        }
        else
        {
            if(p1.y<=p2.y)
            {
                return true;
            }
            return false;
        }
    }
}
long long ccw(point p1, point p2, point p3)
{
    // See 10th slides from following link for derivation
    // of the formula
    ll val = (p2.y - p1.y) * (p3.x - p2.x) -
              (p2.x - p1.x) * (p3.y - p2.y);

   /* if (val == 0) return 0;  // colinear

    return (val > 0)? 1: 2; // clock or counterclock wise*/
    return val;
}

void ccw_sort(vector<point> &v)
{
    vector<point> v1,v2;
    for(int i=0;i<v.size();i++)
    {
        if(v[i].y>0)
        {
            v1.push_back(v[i]);
        }
        else
        {
            v2.push_back(v[i]);
        }
    }
    sort(all(v1),ccw1);
    sort(all(v2),ccw1);
    for(int i=0;i<v2.size();i++)
    {
        v1.push_back(v2[i]);
    }
    v=v1;
}
//Type cast .size() etc. to int or long long int
//Always assume there is an empty subtree in tree stuff like centroid decomp etc.
const int MAXN=80;
int main()
{
    fastio;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    int n,k;
    cin>>n>>k;
    ll adj[MAXN][MAXN];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>adj[i][j];
            if(i==j)
            {
                adj[i][j]=1e13;
            }
        }
    }
    int iter=0;
    int col[MAXN];ll ans=INF;
    while(iter<5000)
    {
        for(int i=0;i<n;i++)
        {
            col[i]=rng()%2;
        }
        ll dp[MAXN][MAXN][10];
        for(int i=0;i<k;i++)
        {
            if(i==0)
            {
                for(int j=0;j<n;j++)
                {
                    for(int l=0;l<n;l++)
                    {
                        if(col[l]==col[j])
                        {
                            dp[l][j][0]=1e13;
                        }
                        else
                        {
                            dp[l][j][0]=adj[l][j];
                        }
                    }
                }
            }
            else
            {
                for(int j=0;j<n;j++)
                {
                    for(int l=0;l<n;l++)
                    {
                        dp[j][l][i]=1e13;
                        for(int m=0;m<n;m++)
                        {
                            if(col[l]!=col[m])
                            {
                                dp[j][l][i]=min(dp[j][l][i],dp[j][m][i-1]+adj[m][l]);
                            }
                        }
                    }
                }
            }
        }
        ans=min(ans,dp[0][0][k-1]);
        iter++;
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <sstream>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<ctime>
#include<cmath>
#include<map>
#include<unordered_map>
#include<stack>
#include<random>
#include<queue>
#include<list>
#include<math.h>
#include<bitset>
#include<fstream>
using namespace std;
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define ii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int> >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define nu 100001
#define mul(x,y) ((ll)(x)*(y))%mod
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < int(n); i++)
const ll INF=9223372036854775807;
const ll mod=1e9+7;
ll  max3(ll  a,ll  b, ll  c)
{
    return max(c,max(a,b));
}
ll min3(ll  a,ll  b,ll  c)
{
    return min(a,min(b,c));
}
ll  power(ll  x,ll  y,ll mod1)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%mod1;
        y = y>>1;
        x = (x*x)%mod1;
    }
    return res;
}
ll  power1(ll  x,ll  y)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}
ll logg(ll  a)
{
    ll  x=0;
    while(a>1)
    {
        x++;
        a/=2;
    }
    return x;
}
ll  gcd(ll  a,ll   b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll abso(ll x)
{
    if(x<0)
    {
        return -x;
    }
    return x;
}
ll ceiling (ll  a,ll  b)
{
    if(a%b==0)
    {
        return a/b;
    }
    else
    {
        return a/b+1;
    }
}
ll modinv(ll x,ll p)
{
    return power(x,p-2,p);
}
struct point
{
    ll x;ll y;
};
ll cross(point a,point b)
{
    return a.x*b.y-b.x*a.y;
}
bool ccw1(point p1,point p2)
{
    /* point n1;n1.x=p1.x-p0.x;n1.y=p1.y-p0.y;
     point n2;n2.x=p2.x-p0.x;n2.y=p2.y-p0.y;*/
    if(cross(p1,p2)>0)
    {
        return true;
    }
    else
    {
        return false;
        //No need to worry about cross=0 case in this question;
    }
}
bool comp(point p1,point p2)
{
    if(p1.x<p2.x)
    {
        return true;
    }
    else
    {
        if(p1.x>p2.x)
        {
            return false;
        }
        else
        {
            if(p1.y<=p2.y)
            {
                return true;
            }
            return false;
        }
    }
}
long long ccw(point p1, point p2, point p3)
{
    // See 10th slides from following link for derivation
    // of the formula
    ll val = (p2.y - p1.y) * (p3.x - p2.x) -
              (p2.x - p1.x) * (p3.y - p2.y);

   /* if (val == 0) return 0;  // colinear

    return (val > 0)? 1: 2; // clock or counterclock wise*/
    return val;
}

void ccw_sort(vector<point> &v)
{
    vector<point> v1,v2;
    for(int i=0;i<v.size();i++)
    {
        if(v[i].y>0)
        {
            v1.push_back(v[i]);
        }
        else
        {
            v2.push_back(v[i]);
        }
    }
    sort(all(v1),ccw1);
    sort(all(v2),ccw1);
    for(int i=0;i<v2.size();i++)
    {
        v1.push_back(v2[i]);
    }
    v=v1;
}
//Type cast .size() etc. to int or long long int
//Always assume there is an empty subtree in tree stuff like centroid decomp etc.
const int MAXN=80;
int main()
{
    fastio;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    int n,k;
    cin>>n>>k;
    ll adj[MAXN][MAXN];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>adj[i][j];
            if(i==j)
            {
                adj[i][j]=1e13;
            }
        }
    }
    int iter=0;
    int col[MAXN];ll ans=INF;
    while(iter<5000)
    {
        for(int i=0;i<n;i++)
        {
            col[i]=rng()%2;
        }
        ll dp[MAXN][MAXN][10];
        for(int i=0;i<k;i++)
        {
            if(i==0)
            {
                for(int j=0;j<n;j++)
                {
                    for(int l=0;l<n;l++)
                    {
                        if(col[l]==col[j])
                        {
                            dp[l][j][0]=1e13;
                        }
                        else
                        {
                            dp[l][j][0]=adj[l][j];
                        }
                    }
                }
            }
            else
            {
                for(int j=0;j<n;j++)
                {
                    for(int l=0;l<n;l++)
                    {
                        dp[j][l][i]=1e13;
                        for(int m=0;m<n;m++)
                        {
                            if(col[l]!=col[m])
                            {
                                dp[j][l][i]=min(dp[j][l][i],dp[j][m][i-1]+adj[m][l]);
                            }
                        }
                    }
                }
            }
        }
        ans=min(ans,dp[0][0][k-1]);
        iter++;
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <sstream>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<ctime>
#include<cmath>
#include<map>
#include<unordered_map>
#include<stack>
#include<random>
#include<queue>
#include<list>
#include<math.h>
#include<bitset>
#include<fstream>
using namespace std;
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define ii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int> >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define nu 100001
#define mul(x,y) ((ll)(x)*(y))%mod
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < int(n); i++)
const ll INF=9223372036854775807;
const ll mod=1e9+7;
ll  max3(ll  a,ll  b, ll  c)
{
    return max(c,max(a,b));
}
ll min3(ll  a,ll  b,ll  c)
{
    return min(a,min(b,c));
}
ll  power(ll  x,ll  y,ll mod1)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%mod1;
        y = y>>1;
        x = (x*x)%mod1;
    }
    return res;
}
ll  power1(ll  x,ll  y)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}
ll logg(ll  a)
{
    ll  x=0;
    while(a>1)
    {
        x++;
        a/=2;
    }
    return x;
}
ll  gcd(ll  a,ll   b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll abso(ll x)
{
    if(x<0)
    {
        return -x;
    }
    return x;
}
ll ceiling (ll  a,ll  b)
{
    if(a%b==0)
    {
        return a/b;
    }
    else
    {
        return a/b+1;
    }
}
ll modinv(ll x,ll p)
{
    return power(x,p-2,p);
}
struct point
{
    ll x;ll y;
};
ll cross(point a,point b)
{
    return a.x*b.y-b.x*a.y;
}
bool ccw1(point p1,point p2)
{
    /* point n1;n1.x=p1.x-p0.x;n1.y=p1.y-p0.y;
     point n2;n2.x=p2.x-p0.x;n2.y=p2.y-p0.y;*/
    if(cross(p1,p2)>0)
    {
        return true;
    }
    else
    {
        return false;
        //No need to worry about cross=0 case in this question;
    }
}
bool comp(point p1,point p2)
{
    if(p1.x<p2.x)
    {
        return true;
    }
    else
    {
        if(p1.x>p2.x)
        {
            return false;
        }
        else
        {
            if(p1.y<=p2.y)
            {
                return true;
            }
            return false;
        }
    }
}
long long ccw(point p1, point p2, point p3)
{
    // See 10th slides from following link for derivation
    // of the formula
    ll val = (p2.y - p1.y) * (p3.x - p2.x) -
              (p2.x - p1.x) * (p3.y - p2.y);

   /* if (val == 0) return 0;  // colinear

    return (val > 0)? 1: 2; // clock or counterclock wise*/
    return val;
}

void ccw_sort(vector<point> &v)
{
    vector<point> v1,v2;
    for(int i=0;i<v.size();i++)
    {
        if(v[i].y>0)
        {
            v1.push_back(v[i]);
        }
        else
        {
            v2.push_back(v[i]);
        }
    }
    sort(all(v1),ccw1);
    sort(all(v2),ccw1);
    for(int i=0;i<v2.size();i++)
    {
        v1.push_back(v2[i]);
    }
    v=v1;
}
//Type cast .size() etc. to int or long long int
//Always assume there is an empty subtree in tree stuff like centroid decomp etc.
const int MAXN=80;
int main()
{
    fastio;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    int n,k;
    cin>>n>>k;
    int adj[MAXN][MAXN];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>adj[i][j];
            if(i==j)
            {
                adj[i][j]=2e9;
            }
        }
    }
    int iter=0;
    int col[MAXN];int ans=2e9;
    while(iter<7000)
    {
        for(int i=0;i<n;i++)
        {
            col[i]=rng()%2;
        }
        int dp[MAXN][11];
        for(int i=1;i<=k;i++)
        {
            if(i==1)
            {
                for(int l=0;l<n;l++)
                {
                    if(col[l]==col[0])
                    {
                        dp[l][1]=2e9;
                    }
                    else
                    {
                        dp[l][1]=adj[0][l];
                    }
                }
            }
            else
            {
                for(int j=0;j<n;j++)
                {
                    dp[j][i]=2e9;
                    for(int l=0;l<n;l++)
                    {
                        if(col[l]!=col[j])
                        {
                            dp[j][i]=min(dp[j][i],dp[l][i-1]+adj[l][j]);
                        }
                    }
                }
            }
        }
        ans=min(ans,dp[0][k]);
        iter++;
    }
    cout<<ans<<endl;
}


//#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <sstream>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<ctime>
#include<cmath>
#include<map>
#include<unordered_map>
#include<stack>
#include<random>
#include<queue>
#include<list>
#include<math.h>
#include<bitset>
#include<fstream>
using namespace std;
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define ii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int> >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define nu 100001
#define mul(x,y) ((ll)(x)*(y))%mod
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < int(n); i++)
const ll INF=9223372036854775807;
const ll mod=1e9+7;
ll  max3(ll  a,ll  b, ll  c)
{
    return max(c,max(a,b));
}
ll min3(ll  a,ll  b,ll  c)
{
    return min(a,min(b,c));
}
ll  power(ll  x,ll  y,ll mod1)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%mod1;
        y = y>>1;
        x = (x*x)%mod1;
    }
    return res;
}
ll  power1(ll  x,ll  y)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}
ll logg(ll  a)
{
    ll  x=0;
    while(a>1)
    {
        x++;
        a/=2;
    }
    return x;
}
ll  gcd(ll  a,ll   b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll abso(ll x)
{
    if(x<0)
    {
        return -x;
    }
    return x;
}
ll ceiling (ll  a,ll  b)
{
    if(a%b==0)
    {
        return a/b;
    }
    else
    {
        return a/b+1;
    }
}
ll modinv(ll x,ll p)
{
    return power(x,p-2,p);
}
struct point
{
    ll x;ll y;
};
ll cross(point a,point b)
{
    return a.x*b.y-b.x*a.y;
}
bool ccw1(point p1,point p2)
{
    /* point n1;n1.x=p1.x-p0.x;n1.y=p1.y-p0.y;
     point n2;n2.x=p2.x-p0.x;n2.y=p2.y-p0.y;*/
    if(cross(p1,p2)>0)
    {
        return true;
    }
    else
    {
        return false;
        //No need to worry about cross=0 case in this question;
    }
}
bool comp(point p1,point p2)
{
    if(p1.x<p2.x)
    {
        return true;
    }
    else
    {
        if(p1.x>p2.x)
        {
            return false;
        }
        else
        {
            if(p1.y<=p2.y)
            {
                return true;
            }
            return false;
        }
    }
}
long long ccw(point p1, point p2, point p3)
{
    // See 10th slides from following link for derivation
    // of the formula
    ll val = (p2.y - p1.y) * (p3.x - p2.x) -
              (p2.x - p1.x) * (p3.y - p2.y);

   /* if (val == 0) return 0;  // colinear

    return (val > 0)? 1: 2; // clock or counterclock wise*/
    return val;
}

void ccw_sort(vector<point> &v)
{
    vector<point> v1,v2;
    for(int i=0;i<v.size();i++)
    {
        if(v[i].y>0)
        {
            v1.push_back(v[i]);
        }
        else
        {
            v2.push_back(v[i]);
        }
    }
    sort(all(v1),ccw1);
    sort(all(v2),ccw1);
    for(int i=0;i<v2.size();i++)
    {
        v1.push_back(v2[i]);
    }
    v=v1;
}
//Type cast .size() etc. to int or long long int
//Always assume there is an empty subtree in tree stuff like centroid decomp etc.
const int MAXN=80;
int main()
{
    fastio;
    int n,k;
    cin>>n>>k;
    int adj[MAXN][MAXN];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>adj[i][j];
        }
    }
    //vector<vll> temp=adj;
    vector<int> dp[MAXN][MAXN];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            for(int kk=0;kk<n;kk++)
            {
                if(kk!=i&&kk!=j){
                dp[i][j].push_back(adj[i][kk]+adj[kk][j]);
                }
            }
            sort(all(dp[i][j]));
           // reverse(all(dp[i][j]));
        }
    }
    ll ans=INF;int app[MAXN][MAXN];
    for(int i=0;i<MAXN;i++)
    {
        for(int j=0;j<MAXN;j++)
        {
            app[i][j]=-1;
        }
    }
    int x=power1(n,(k/2)-1);
    for(int j=0;j<(x);j++)
    {
        vector<int> cur;int jj=j;vi tp;
        for(int m=0;m<(k/2)-1;m++)
        {
            cur.push_back(jj%n);
            //tp.push_back(jj%n);
            jj=jj/n;
        }
        tp=cur;
        tp.push_back(0);
        sort( tp.begin(), tp.end() );
        tp.erase( unique( tp.begin(), tp.end() ), tp.end() );
        int prev=0;cur.push_back(0);
        ll val=0;
        for(int ind=0;ind<cur.size();ind++)
        {
            int y=-1;
            if(app[prev][cur[ind]]!=-1)
            {
                y=app[prev][cur[ind]];
            }else{
            vi tmp;
            for(int j=0;j<tp.size();j++)
            {
                if(prev!=tp[j]&&cur[ind]!=tp[j])
                {
                    tmp.push_back(adj[prev][tp[j]]+adj[tp[j]][cur[ind]]);
                }
            }
                sort(all(tmp));int jjj=0;
            for(int x=0;x<(int)dp[prev][cur[ind]].size();x++)
            {
                if(jjj>=(int)tmp.size()||dp[prev][cur[ind]][x]!=tmp[jjj])
                {
                    y=dp[prev][cur[ind]][x];
                    break;
                }
                else{
                    jjj++;
                }
            }}
            app[prev][cur[ind]]=-1;
            if(y==-1)
            {
                val=-1;
                break;
            }
            else{
                val+=y;
            }
            prev=cur[ind];
        }
        prev=0;
        for(int ind=0;ind<cur.size();ind++)
        {
            app[prev][cur[ind]]=-1;
        }
        if(val==-1)
        {
            continue;
        }
        else
        {
            ans=min(ans,val);
        }

    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 80;
const int maxk = 10;
const int inf = 0x3f3f3f3f;

int n, k;
int w[maxn][maxn], col[maxn], f[maxn], nf[maxn];

unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 rand_num(seed);

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			scanf("%d", &w[i][j]);
			if (i == j) w[i][i] = inf;
		}
	}
	int T = 5000, ans = inf;
	while (T --) {
		for (int i = 0; i < n; i++) col[i] = rand_num() % 2;
		for (int i = 0; i < n; i++) f[i] = inf;
		f[0] = 0;
		for (int i = 0; i < k; i++) {
			for (int j = 0; j < n; j++) {
				nf[j] = inf;
				for (int k = 0; k < n; k++) {
					if (col[k] != col[j])
						nf[j] = min(nf[j], f[k] + w[k][j]);
				}
			}
			for (int j = 0; j < n; j++) f[j] = nf[j];
		}
		for (int i = 0; i < n; i++) ans = min(ans, f[0]);
	}
	printf("%d\n", ans);
	return 0;
}