module Main where

import Data.List
import Control.Monad
import Debug.Trace
import Data.Bits
import Data.Array.MArray
import Data.Array.ST
import Control.Monad.ST
import Control.Applicative
import Data.STRef

type UnionFind s = STArray s Int Int
newUnionFind :: Int -> Int -> ST s (UnionFind s)
newUnionFind start end = newListArray (start, end) [start..end]

root :: UnionFind s -> Int -> ST s Int
root u i = do
    parent <- readArray u i
    if parent == i then pure parent
    else do
        parent' <- root u parent
        writeArray u i parent'
        pure parent'

unite :: UnionFind s -> Int -> Int -> ST s ()
unite u ix iy = do
    rx <- root u ix
    ry <- root u iy
    if rx == ry then pure ()
    else writeArray u rx ry

same :: UnionFind s -> Int -> Int -> ST s Bool
same u x y = liftA2 (==) (root u x) (root u y)

size :: UnionFind s -> Int -> ST s Int
size u i = do
    (min, max) <- getBounds u
    foldM inner 0 [min..max] 
    where
    inner acc index = do
        isSame <- same u i index 
        if isSame then pure (acc + 1) else pure acc


solve :: Int -> [Bridge] -> [String]
solve islands bs = runST $ do
    let bs' = reverse $ tail bs
    let initialHuben = islands * (islands -1) `div` 2
    huben <- newSTRef initialHuben
    ans <- newSTRef [show initialHuben] 
    u <- newUnionFind 1 islands
    forM_ bs' $ \b -> do
        let (x, y) = b
        isSame <- same u x y 
        if isSame then do
            huben' <- readSTRef huben
            ans' <- readSTRef ans
            writeSTRef ans (show huben' : ans')
        else do
            huben' <- readSTRef huben
            sizex <- size u x
            sizey <- size u y
            let newHuben = huben' - sizex * sizey
            writeSTRef huben newHuben
            ans' <- readSTRef ans
            writeSTRef ans (show newHuben : ans')
            unite u x y
    readSTRef ans



        


type Bridge = (Int, Int)

readBridge :: IO Bridge
readBridge = do
    [s, e] <- fmap read . words <$> getLine
    pure (s, e)

main = do
    [n, m] <- fmap read . words <$> getLine
    bridges <- replicateM m readBridge
    putStrLn $ unlines $ solve n bridges
