module uf
  implicit none
  integer(8) :: unionfind(100000) = -1

contains

  recursive function root(i) result(res)
    integer(8),intent(in) :: i
    integer(8) res

    if (unionfind(i) < 0) then
       res = i
    else
       unionfind(i) = root(unionfind(i))
       res = unionfind(i)
    end if
  end function root

  subroutine unite(a, b)
    integer(8),intent(in) :: a,b

    if (unionfind(a) < unionfind(b)) then
       unionfind(a) = unionfind(a) + unionfind(b)
       unionfind(b) = a
    else
       unionfind(b) = unionfind(b) + unionfind(a)
       unionfind(a) = b
    end if
  end subroutine unite

end module uf

program abc120d
  use uf
  implicit none
  integer(8) n, m, i, ra, rb
  integer(8),dimension(:),allocatable :: a, b, ans

  read *, n,m
  allocate(a(m),b(m),ans(m))

  do i = 1,m
     read *, a(i),b(i)
  end do

  ans(m) = n*(n-1)/2

  do i = m,2,-1
     ans(i-1) = ans(i)
     ra = root(a(i))
     rb = root(b(i))
     if (ra /= rb) then
        ans(i-1) = ans(i-1)-unionfind(ra)*unionfind(rb)
        call unite(ra,rb)
     end if
  end do

  do i = 1,m
     print *, ans(i)
  end do

end program abc120d
