import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.IntMap as IM
import Data.Bool (bool)
import Data.List (mapAccumR)

main :: IO ()
main = do
  [n, m] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    comp0 = IM.empty :: UF
    size0 = IM.empty :: IM.IntMap Int
    f :: [(Int, Int)] -> [Int]
    f = snd . mapAccumR step (comp0, size0)
      where
        step :: (UF, IM.IntMap Int) -> (Int, Int) -> ((UF, IM.IntMap Int), Int)
        step (u, v) (i, j)
          | b
              = ((u', v), 0)
          | otherwise
              = let
                    vi = IM.findWithDefault 1 (snd $ root i u') v :: Int
                    vj = IM.findWithDefault 1 (snd $ root j u') v :: Int
                    (u'', v') = unite i j v u' :: (UF, IM.IntMap Int)
                    vij = v' IM.! (snd $ root j u'')
                    c' = count vij - count vi - count vj
                  in
                    ((u'', v'), c')
          where
            (u', b) = isSame i j u :: (UF, Bool)
  abs <- sequence . replicate m $ unsafeListToPair . map unsafeTextToInt . T.words <$> T.getLine :: IO [(Int, Int)]
  mapM_ print . tail . scanl (+) 0 . f $ abs

count :: Int -> Int
count k = k * pred k `div` 2
{-# INLINE count #-}

type UF = IM.IntMap Int

parent :: Int -> UF -> Maybe Int
parent = IM.lookup
{-# INLINE parent #-}

root :: Int -> UF -> (UF, Int)
root i u = maybe (u, i) (\j -> let (u', j') = root j u in (bool (IM.insert i j' u') u (j' == j), j')) (parent i u)
{-# INLINE root #-}

unite :: Int -> Int -> IM.IntMap Int -> UF -> (UF, IM.IntMap Int)
unite i j v u | i' == j'  = (u'', v)
              | otherwise = (IM.insert j' i' u'', v')
  where
    (u', i') = root i u
    (u'', j') = root j u'
    v' = IM.insert i' (vi + vj) v
      where
        vi = IM.findWithDefault 1 i' v :: Int
        vj = IM.findWithDefault 1 j' v :: Int
{-# INLINE unite #-}

isSame :: Int -> Int -> UF -> (UF, Bool)
isSame i j u = (u'', i' == j')
  where
    (u', i') = root i u
    (u'', j') = root j u'
{-# INLINE isSame #-}

unsafeListToPair :: [a] -> (a, a)
unsafeListToPair [x, y] = (x, y)
{-# INLINE unsafeListToPair #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}
