void main()
{
    long[] tmp = rdRow;
    long n = tmp[0], m = tmp[1];
    Cake[] c = n.rdCol!Cake;

    long result;
    foreach (i; 0 .. 8)
    {
        long num = i;
        bool[] lists = new bool[3];
        foreach (j; 0 .. 3)
        {
            lists[j] = num & 1;
            num >>= 1;
        }
        c.sort!((x, y) => x.comp(lists) > y.comp(lists));
        Cake total;
        foreach (j; 0 .. m)
        {
            total += c[j];
        }
        result = max(result, total.value);
    }

    result.writeln;
}

struct Cake
{
    long x, y, z;

    Cake opBinary(string op)(Cake that)
    if (op == "+" || op == "-")
    {
        Cake result;
        result.x = mixin("this.x "~op~" that.x");
        result.y = mixin("this.y "~op~" that.y");
        result.z = mixin("this.z "~op~" that.z");
        return result;
    }

    Cake opOpAssign(string op)(Cake that)
    if (op == "+" || op == "-")
    {
        return mixin("this = this "~op~" that");
    }

    long comp(bool[] arr)
    {
        return this.x * (-1) ^^ arr[0] + this.y * (-1) ^^ arr[1] + this.z * (-1) ^^ arr[2];
    }

    long value()
    {
        return this.x.abs + this.y.abs + this.z.abs;
    }
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;