import sys input = sys.stdin.readline n=int(input()) m=int(input()) A=[list(map(int,input().split())) for i in range(m)] DP=[A] for tests in range(32): X=DP[-1] Y=[[0]*m for i in range(m)] for i in range(m): for j in range(m): for k in range(m): Y[i][j]=max(Y[i][j],X[i][k]+X[k][j]) DP.append(Y) NOW=[[0]*m for i in range(m)] n-=1 for b in range(31,-1,-1): if n>=(1<