{-# LANGUAGE MultiWayIf #-}

import           Control.Monad (replicateM)
import           Data.Foldable (for_)
import           Data.List     (intersect, mapAccumL, partition)

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
type Convenience = Int

solve :: Int -> [Bridge] -> [Inconvenience]
solve n = (++ [maxInconvenience]) . tail . map (maxInconvenience -) . reverse . snd . mapAccumL f (0, []) . reverse
  where
    f :: (Convenience, [[Island]]) -> Bridge -> ((Convenience, [[Island]]), Convenience)
    f (convenience, islandGroups) (i1, i2) =
      let
        (contain1, notContain1) = partition (i1 `elem`) islandGroups
        (contain2, notContain2) = partition (i2 `elem`) islandGroups
        contain12 = contain1 `intersect` contain2
        onlyContain1 = contain1 `intersect` notContain2
        onlyContain2 = notContain1 `intersect` contain2
        containNeither = notContain1 `intersect` notContain2
        (change, next) =
          if
            | not $ null contain12 -> (0, islandGroups)
            | not (null onlyContain1) && not (null onlyContain2) ->
              (length (head onlyContain1) * length (head onlyContain2), (head onlyContain1 ++ head onlyContain2) : containNeither)
            | not $ null onlyContain1 ->
              (length $ head onlyContain1, (i2 : head onlyContain1) : containNeither)
            | not $ null onlyContain2 ->
              (length $ head onlyContain2, (i1 : head onlyContain2) : containNeither)
            | otherwise -> (1, [i1, i2] : islandGroups)
        convenience' = convenience + change
      in
        ((convenience', next), convenience')

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