def gl $stdin.gets.chomp end N = gl.to_i M = gl.to_i scores = (0...M).map{ gl.split(" ").map{ |a| a.to_i } } status = (0...M).map{ 0 } (N-1).times { ns = (0...M).map{ |j| (0...M).map{ |i| scores[i][j] + status[i] }.max } status = ns } puts status.max