fun main(args: Array<String>) {
    val arr = readLine()!!.split(" ").map { s->s.toInt() }
    val n = arr[0]
    val m = arr[1]
    val unionFind = UnionFind(n)

    val bridges = Array(m) {
        readLine()!!.split(" ").map { s->s.toInt()-1 }
    }
    val count:Long = n.toLong()*(n-1)/2
    val result = Array(m){ count }
    for(i in 1 until m){
        val bridge = bridges[m-i]
        if(!unionFind.same(bridge[0],bridge[1])){
            result[i]=result[i-1]-unionFind.size(bridge[0])*unionFind.size(bridge[1])
            unionFind.unite(bridge[0],bridge[1])
        }else{
            result[i]=result[i-1]
        }
    }
    result.reverse()
    result.forEach { println(it) }
}

class UnionFind(size:Int){
    private val parents: Array<Int?> =  arrayOfNulls(size)
    private val sizes: Array<Int> =  Array(size) { i -> 1}

    fun root(node: Int):Int{
        return if (parents[node] == null){
            node
        }else{
            parents[node]=root(parents[node]!!)
            parents[node]!!
        }
    }

    fun unite(u:Int,v:Int){
        var ur = root(u)
        var vr = root(v)
        if(sizes[ur]>sizes[vr]){
            ur = vr .apply{vr=ur}
        }
        parents[ur] = vr
        sizes[vr] += sizes[ur]
    }

    fun same(u:Int,v:Int):Boolean = root(u)==root(v)

    fun size(u:Int):Int = sizes[root(u)]
}