import Control.Monad
  ( replicateM )
import Data.List

data R a = R { kaisu :: Int
             , rep   :: a 
             }
  deriving (Show)

main :: IO ()
main = do
  [n,m] <- map read . words <$> getLine
  abs   <- replicateM m $ map read . words <$> getLine :: IO [[Int]]
  mapM_ print $ honsu' n abs

toR :: [Int] -> Int -> R Int
toR as n
  | null as   = R 0 n
  | a == n    = R l a
  | otherwise = error "toR: "
  where
    a = head as
    l = length as
    
honsu'    
  :: Int -> [[Int]] -> [Int]
honsu' n as = map kaisu . zipWith toR (group . sort . concat $ as) $ [1..n]