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 dbgpr_t2d(tbl2d)
    if DBG then
        dbgpr(tbl2d)
        for i,t in ipairs(tbl2d) do
            io.write("[dbg]")
            for j,v in ipairs(t) do
                io.write("(" .. tostring(i) .. "," .. tostring(j) .. "): ")
                io.write(tostring(v))
                io.write("; ")
            end
            print("")
        end
    end
end

function create_tbl(a, initial)
    local tbl = {}
    for i=1,a do
        tbl[i] = initial
    end
    return tbl
end

function create_2d_tbl(a, b, initial)
    local tbl = {}
    for i=1,a do
        local t = {}
        for j=1,b do
            t[j] = initial
        end
        tbl[i] = t
    end
    return tbl
end

function parse_problem()
    local N, M = io.read("n", "n")
    local bridges = {}
    for i=1, M do
        local a, b = io.read("n", "n")
        bridges[i] = {a, b}
    end
    return N, M, bridges
end

perf = 0

function main()
    local N, M, bridges = parse_problem()
    parents = {}
    for i=1,N do
        parents[i] = -1
    end
    local function find_union(a, b)
        local x, y = a, b
        while parents[x] > 0 do
            x = parents[x]
        end
        while parents[y] > 0 do
            y = parents[y]
        end
        local size_a, size_b = -parents[x], -parents[y]
        if x ~= y then
            parents[x] = parents[x] + parents[y]
            parents[y] = x
        end
        return x == y, size_a, size_b
    end
    dbgpr(N, M)
    dbgpr("====bridges")
    dbgpr_t2d(bridges)
    local ans_tbl = {}
    ans_tbl[M] = N * (N - 1) // 2
    dbgpr("M, ansM: ", M, ans_tbl[M])
    for i=M,1,-1 do
        local a, b = bridges[i][1], bridges[i][2]
        local same_group, size_a, size_b = find_union(a, b)
        --dbgpr(i, a, b, same_group, size_a, size_b, size_a * size_b)
        if same_group then
            ans_tbl[i-1] = ans_tbl[i]
        else
            ans_tbl[i-1] = ans_tbl[i] - size_a * size_b
        end
    end
    for i=1,M do
        print(ans_tbl[i])
    end
end

main()
