#include using namespace std; typedef long long ll; #define REP(i,n) FOR(i,0,n) #define FOR(i,a,b) for(ll i=a;i vi; typedef vector> vvi; const ll INF = (1ll << 30); typedef pair pii; struct Edge{ ll s,t,c; }; typedef vector> Graph; typedef vector vpii; int main() { ll n,m; cin>>n>>m; vvi a(m,vi(m)); REP(i,m) REP(j,m) cin>>a[i][j]; vvi dp(m,vi(n)); FOR(i,1,n) { REP(j,m) { REP(k,m) { dp[j][i]=max(dp[j][i],dp[k][i-1]+a[k][j]); } } } ll ans=0; REP(i,m) ans=max(ans,dp[i][n-1]); cout<