module mod1
implicit none
integer(8) :: par(0:200000),count(0:200000)=0,kodomo(0:200000)=1,temp1,temp2,temp3
end module mod1

program test
use mod1 
implicit none

integer(8) :: n,q,i,j,k,m
integer(8) :: p(0:200000),a(0:200000),b(0:200000)

read(*,*) n,m
do i=m,1,-1
	read(*,*) a(i),b(i)
enddo

!親の番号
do i=0,n
	par(i) = i
enddo

do i=1,m
	if(root(a(i)) .eq. root(b(i)))then
		count(i) = count(i-1)
		continue
	else
		!子、親
		temp1 = (kodomo(root(b(i)))+kodomo(root(a(i))))*(kodomo(root(b(i)))+kodomo(root(a(i)))-1)/2
		temp2 = (kodomo(root(a(i))))*(kodomo(root(a(i)))-1)/2
		temp3 = (kodomo(root(b(i))))*(kodomo(root(b(i)))-1)/2
		count(i) = count(i-1) + temp1 - temp2 - temp3
		kodomo(root(b(i))) = kodomo(root(b(i))) + kodomo(root(a(i)))
		kodomo(root(a(i))) = 1
		call unite(a(i),b(i))
	endif
enddo

do i=m-1,0,-1
	write(*,*) count(m) - count(i)
enddo

contains
recursive function root(x) result(res)
integer(8) :: x,res
	if(par(x) == x) then
		continue
	else
		par(x) = root(par(x))
	endif
	res = par(x)
end function

subroutine unite(x,y)
integer(8) :: x,y
x = root(x)
y = root(y)
if(x .ne. y) then
	par(x) = y
endif
end subroutine


end program