fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val list = (1..m).map { readLine()!!.split(" ").map { it.toInt() } }.reversed()

    val ans = mutableListOf<Long>()
    val uf = UnionFind(n)

    var cur = (n.toLong() * (n.toLong() - 1)) / 2

    for (ab in list) {
        ans.add(cur)

        val a = ab[0] - 1
        val b = ab[1] - 1

        if (uf.isSame(a, b)) {
            continue
        }

        val sizeA = uf.size(a)
        val sizeB = uf.size(b)
        cur -= sizeA * sizeB

        uf.merge(a, b)
    }

    ans.reversed().forEach{ println(it) }
}

private class UnionFind(n: Int) {
    val parent = Array(n) { -1 }

    fun root(x: Int): Int {
        return if (parent[x] < 0) {
            x
        } else {
            parent[x] = root(parent[x])
            parent[x]
        }
    }

    fun isSame(x: Int, y: Int): Boolean {
        return root(x) == root(y)
    }

    fun merge(x: Int, y: Int): Boolean {
        var xRoot = root(x)
        var yRoot = root(y)
        if (xRoot == yRoot) {
            return false
        }

        // merge technique
        if (parent[xRoot] > parent[yRoot]) {
            val tmp = yRoot
            yRoot = xRoot
            xRoot = tmp
        }

        parent[xRoot] += parent[yRoot];
        parent[yRoot] = xRoot
        return true
    }

    fun size(x: Int): Int {
        return -parent[root(x)]
    }
}
