program main
  implicit none
  integer :: n, m, i, j, tmp
  integer, allocatable :: a(:), b(:), parents(:), cnt(:), res(:)
  read (*, *) n, m
  allocate (a(m), b(m), parents(n), cnt(n), res(m))
  do j = 1, m
    read (*, *) a(j), b(j)
  end do

  parents = [(i, i = 1, n)]
  cnt(:) = 1

  tmp = n * (n - 1) / 2
  do j = m, 1, -1
    res(j) = tmp
    if (find(a(j), parents) /= find(b(j), parents)) then
      tmp = tmp - cnt(find(a(j), parents)) * cnt(find(b(j), parents))
      call unite(a(j), b(j), parents, cnt)
    end if
  end do

  do j = 1, m
    print "(i0)", res(j)
  end do

  contains

  subroutine unite(x, y, parents, cnt)
    ! Insert y to x
    integer, intent(in) :: x, y
    integer, intent(inout) :: parents(:), cnt(:)
    integer :: px, py
    px = find(x, parents)
    py = find(y, parents)
    if (px /= py) then
      parents(py) = px
      cnt(px) = cnt(px) + cnt(py)
    end if
  end subroutine unite

  recursive function find(x, parents) result(r)
    integer, intent(in) :: x
    integer, intent(inout) :: parents(:)
    integer :: r
    if (parents(x) == x) then
      r = x
    else
      r = find(parents(x), parents)
      parents(x) = r
    end if
  end function find
end program main
