#include using namespace std; #define ALL(x) x.begin(),x.end() #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const pair&p){ os< ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,pair&p){ is>>p.first>>p.second; return is; } template istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } int m; vector> Tropical(vector> &a,vector> &b){ vector> ret(m,vector(m,0)); // i->j->k rep(i,m)rep(j,m)rep(k,m) chmax(ret[i][k],a[i][j]+b[j][k]); return ret; } vector> PLight(vector> a,ll n){ vector> ret(m,vector(m,0)); while(n){ if(n&1) ret=Tropical(ret,a); a=Tropical(a,a); n>>=1; } return ret; } signed main(){ ll n;cin>>n;n--; cin>>m; vector> mat(m,vector(m)); rep(i,m)rep(j,m){ cin>>mat[i][j]; } mat=PLight(mat,n); ll res=0; rep(i,m)rep(j,m)chmax(res,mat[i][j]); cout<