{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE RecordWildCards       #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import qualified Data.Foldable               as F
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Unsafe.Coerce

main :: IO ()
main = do
    [n, m] <- map read.words <$> getLine :: IO [Int]
    xys <- U.unfoldrN m parseInt2 <$> B.getContents
    putStr.unlines.map show $ solve n m xys

solve :: Int -> Int -> U.Vector (Int, Int) -> [Int]
solve n m xys = runST $ do
    uf <- newUnionFind n
    let go !acc !res ((x, y):rest) = do
            px <- findM uf $ x - 1
            py <- findM uf $ y - 1
            if px == py
            then go acc (acc:res) rest
            else do
                sx <- sizeM uf $ x - 1
                sy <- sizeM uf $ y - 1
                uniteM uf (x - 1) (y - 1)
                go (acc - sx * sy) (acc:res) rest
        go _ res [] = return res
    go (n * (n - 1) `div` 2) [] . U.toList $ U.reverse xys

-------------------------------------------------------------------------------
type Parser a = B.ByteString -> Maybe (a, B.ByteString)

parseInt :: Parser Int
parseInt = B.readInt . B.dropWhile isSpace

parseInt2 :: Parser (Int, Int)
parseInt2 = runStateT $
    (,) <$> StateT (B.readInt . B.dropWhile isSpace)
        <*> StateT (B.readInt . B.unsafeTail)

parseInt3 :: Parser (Int, Int, Int)
parseInt3 = runStateT $
    (,,) <$> StateT (B.readInt . B.dropWhile isSpace)
        <*> StateT (B.readInt . B.unsafeTail)
        <*> StateT (B.readInt . B.unsafeTail)

parseInt4 :: Parser (Int, Int, Int, Int)
parseInt4 = runStateT $
    (,,,) <$> StateT (B.readInt . B.dropWhile isSpace)
        <*> StateT (B.readInt . B.unsafeTail)
        <*> StateT (B.readInt . B.unsafeTail)
        <*> StateT (B.readInt . B.unsafeTail)
data UnionFind m = UF
    { parent :: UM.MVector m Int
    , rank   :: UM.MVector m Int
    , size   :: UM.MVector m Int
    }

nothing :: Int
nothing = -1
{-# INLINE nothing #-}

newUnionFind :: PrimMonad m => Int -> m (UnionFind (PrimState m))
newUnionFind n = UF
    `liftM` UM.replicate n nothing
    `ap` UM.replicate n 0
    `ap` UM.replicate n 1
{-# INLINE newUnionFind #-}

findM :: PrimMonad m => UnionFind (PrimState m) -> Int -> m Int
findM uf@UF{..} x = do
    px <- UM.unsafeRead parent x
    if px == nothing
    then return x
    else do
        ppx <- findM uf px
        UM.unsafeWrite parent x ppx
        return ppx
{-# INLINE findM #-}

sizeM :: PrimMonad m => UnionFind (PrimState m) -> Int -> m Int
sizeM uf@UF{..} x = do
    px <- findM uf x
    UM.unsafeRead size px

uniteM :: PrimMonad m => UnionFind (PrimState m) -> Int -> Int -> m ()
uniteM uf@UF{..} x y= do
    px <- findM uf x
    py <- findM uf y
    when (px /= py) $ do
        rx <- UM.unsafeRead rank px
        ry <- UM.unsafeRead rank py
        case compare rx ry of
            LT -> do
                UM.unsafeWrite parent px py
                sx <- UM.unsafeRead size px
                UM.unsafeModify size (+sx) py
            GT -> do
                UM.unsafeWrite parent py px
                sy <- UM.unsafeRead size py
                UM.unsafeModify size (+sy) px
            EQ -> do
                UM.unsafeWrite parent px py
                sx <- UM.unsafeRead size px
                UM.unsafeModify size (+sx) py
                UM.unsafeWrite rank py (ry + 1)
{-# INLINE uniteM #-}

equivM :: PrimMonad m => UnionFind (PrimState m) -> Int -> Int -> m Bool
equivM uf x y = (==) `liftM` findM uf x `ap` findM uf y
{-# INLINE equivM #-}

-- | O(n)
countGroupM :: PrimMonad m => UnionFind (PrimState m) -> m Int
countGroupM UF{..} = U.length . U.filter (==nothing) <$> U.unsafeFreeze parent
{-# INLINE countGroupM #-}

Measured memory_bytes: 12412