program main
	implicit none
	integer N, M, i, j
	integer(8), allocatable :: x(:), y(:), z(:), Sx(:, :), Sy(:, :), Sz(:, :), dp(:, :)
	read(*, *) N, M
	allocate(x(1: N))
	allocate(y(1: N))
	allocate(z(1: N))
	allocate(Sx(0:N, 0:M))
	allocate(Sy(0:N, 0:M))
	allocate(Sz(0:N, 0:M))
	allocate(dp(0:N, 0:M))
	do i = 1, N
		read(*, *) x(i), y(i), z(i)
	end do
	Sx(0, 0:M) = 0
	Sx(0:N, 0) = 0
	Sy(0, 0:M) = 0
	Sy(0:N, 0) = 0
	Sz(0, 0:M) = 0
	Sz(0:N, 0) = 0	
	dp(0, 0:M) = 0
	dp(0:N, 0) = 0
	do i = 1, N
		do j = 1, M
			Sx(i, j) = Sx(i-1, j-1) + x(i)
			Sy(i, j) = Sy(i-1, j-1) + y(i)
			Sz(i, j) = Sz(i-1, j-1) + z(i)
			if(dp(i-1,j) < abs(Sx(i, j))+ abs(Sy(i, j))+ abs(Sz(i, j))) then
				dp(i, j) = abs(Sx(i, j))+ abs(Sy(i, j)) + abs(Sz(i, j))
			else
				dp(i, j) = dp(i-1, j)
				Sx(i, j) = Sx(i-1, j) 
				Sy(i, j) = Sy(i-1, j) 
				Sz(i, j) = Sz(i-1, j)
			end if
		end do
	end do
	write(*, *) dp(N, M)
end program main