local DBG = false
function dbgpr(...)
    if DBG then
        io.write("[dbg]")
        print(...)
    end
end
function dbgpr_t(tbl)
    if DBG then
        dbgpr(tbl)
        io.write("[dbg]")
        for i,v in ipairs(tbl) do
            io.write(i)
            io.write(":")
            io.write(tostring(v))
            io.write(" ")
        end
        print("")
    end
end

function parse_problem()
    local N = io.read("n")
    local M = io.read("n")
    local goals = {}
    for i=1,M do
        local l, _ = io.read("n")
        table.insert(goals, l)
    end
    return N, M, goals
end

function main()
    local N, M, goals = parse_problem()
    table.sort(goals)
    local INF = 10000000
    local diffs = {}
    for i=1, #goals-1 do
        diffs[i] = goals[i + 1] - goals[i]
    end
    table.sort(diffs)
    dbgpr_t(goals)
    dbgpr_t(diffs)
    if N >= M then
        print(0)
    else
        local sum = 0
        for i=1, M-N do
            sum = sum + diffs[i]
        end
        print(sum)
    end
end
main()
