import           Control.Monad (replicateM)
import           Data.Foldable (for_)
import           Data.List     (intersect, mapAccumL, partition)
import qualified Data.List     as L (find)
import           Data.Maybe    (fromJust)
import           Data.Vector   (Vector, (!), (//))
import qualified Data.Vector   as V (enumFromTo, generate)

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  bridges <- replicateM m $ do
    [a, b] <- map read . words <$> getLine
    pure (a, b)
  for_ (solve n bridges) print

type Island = Int
type Bridge = (Island, Island)
type Inconvenience = Int

solve :: Int -> [Bridge] -> [Inconvenience]
solve n = reverse . snd . mapAccumL f (maxInconvenience, toUnionFind' n) . reverse
  where
    f ::
      (Inconvenience, UnionFind' Island) ->
      Bridge ->
      ((Inconvenience, UnionFind' Island), Inconvenience)
    f (inconvenience, islandGroups) (i1, i2) =
      let
        (s1, contain1) = find' i1 islandGroups
        (s2, contain2) = find' i2 islandGroups

        bothContained = contain1 == contain2

        inconvenience' =
          inconvenience - (if bothContained then 0 else s1 * s2)
        islandGroups' =
          if bothContained then islandGroups else union' i1 i2 islandGroups
      in
        ((inconvenience', islandGroups'), inconvenience)

    maxInconvenience :: Inconvenience
    maxInconvenience = n * (n - 1) `div` 2

type Size = Int
type UnionFind' a = Vector (Size, a)

toUnionFind' :: Int -> UnionFind' Int
toUnionFind' n = (1,) <$> V.enumFromTo 0 n

find' :: Int -> UnionFind' Int -> (Size, Int)
find' i uf =
  let
    (s, i') = uf ! i
  in
    if i' == i
      then (s, i)
      else find' i' uf

union' :: Int -> Int -> UnionFind' Int -> UnionFind' Int
union' i1 i2 uf =
  let
    (s1, representative1) = find' i1 uf
    (s2, representative2) = find' i2 uf
  in
    if representative1 == representative2
    then uf
    else uf // [(representative1, (s1, representative2)), (representative2, (s1 + s2, representative2))]

-- size :: Int -> UnionFind' Int -> Int

type UnionFind a = [[a]]

toUnionFind :: [a] -> UnionFind a
toUnionFind = map pure

find :: Eq a => a -> UnionFind a -> [a]
find x xss = fromJust $ L.find (x `elem`) xss

union :: Eq a => a -> a -> UnionFind a -> UnionFind a
union x1 x2 xss =
  let
    (contain1, notContain1) = partition (x1 `elem`) xss
    (contain2, notContain2) = partition (x2 `elem`) xss
    containNeither = notContain1 `intersect` notContain2
  in
    (head contain1 ++ head contain2) : containNeither

-- size :: Eq a => a -> [[a]] -> Int
-- size = (length .) . find
