module m1
  implicit none
  integer(8) :: u(100000) = -1
contains
  recursive integer(8) function root(i) result(res)
    integer(8), intent(in) :: i
    if (u(i) < 0) then
       res = i
    else
       u(i) = root(u(i))
       res = u(i)
    end if
  end function root
end module m1
program abc120d
  use m1
  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) - u(ra) * u(rb)
        if (u(ra) < u(rb)) then
           u(ra) = u(ra) + u(rb)
           u(rb) = ra
        else
           u(rb) = u(rb) + u(ra)
           u(ra) = rb
        end if
     end if
  end do
  do i = 1, m
     print '(i0)', ans(i)
  end do
end program abc120d
