{-# LANGUAGE BangPatterns #-}
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 (Maybe Int), STArray s Int Int)
newUnionFind :: Int -> Int -> ST s (UnionFind s)
newUnionFind start end = liftA2 (,) (newArray (start, end) Nothing) (newArray (start, end) 1)

root :: UnionFind s -> Int -> ST s Int
root (u, t) i = do
    parent <- readArray u i
    parent <- case parent of
        Nothing -> do
            writeArray u i $ Just i
            pure i
        Just p ->
            pure p
    if parent == i then pure parent
    else do
        parent' <- root (u, t) parent
        writeArray u i (Just parent')
        pure parent'

unite :: UnionFind s -> Int -> Int -> ST s ()
unite (u, total) ix iy = do
    rx <- root (u, total) ix
    ry <- root (u, total) iy
    if rx == ry then pure ()
    else do 
        sizex <- size (u, total) rx 
        sizey <- size (u, total) ry
        writeArray u rx (Just ry)
        writeArray total ry (sizex + sizey)

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, t) i = (root (u, t) i) >>= readArray t


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 
        huben' <- readSTRef huben
        ans' <- readSTRef ans
        if huben' == 0 then
            writeSTRef ans ("0" : ans')
        else if isSame then 
            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
            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
