import java.util.*

fun main(args: Array<String>) {

    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    val M = sc.nextInt()
    val ans = LongArray(M+1){0L}
    ans[M] = N.toLong()*(N-1)/2

    val map = mutableMapOf<Int,Int>()
    Array(N){it+1 to -1}.toMap(map)

    fun root(n:Int) :Int {
        return if (map[n]!!<0) n
        else {
            map[n] = root(map[n]!!)
            map[n]!!
        }
    }

    fun size(n:Int) = -map[root(n)!!]!!

    val bridge = Array(M){0 to 0}
    for (i in 0 until M) {
        val A = sc.nextInt()
        val B = sc.nextInt()
        bridge[i] = A to B
    }
    for (i in M-1 downTo 0) {
        ans[i] = ans[i+1]
        var (a,b) = bridge[i]
        var A = root(a)
        var B = root(b)
        if (A == B) continue
        ans[i] -= size(A)*size(B).toLong()

        if (size(A) < size(B)) {
            val tmp = A
            A = B
            B = tmp
        }
        map[A] = -size(A) - size(B)
        map[B] = A
        //println(map)
    }
    for (l in 1 .. M) println(ans[l])
}