import qualified Data.ByteString.Char8 as C
import Control.Monad -- ( replicateM )
import Data.List ( sort, group )
import Data.Maybe ( fromJust )

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  [n,m] <- readInts
  abs   <- replicateM m C.getLine
  mapM_ print $ honsu n abs

honsu
  :: Int -> [C.ByteString] -> [Int]
honsu n as = map length' . C.group . C.sort . C.concat $ (one2n : as)
  where
    one2n :: C.ByteString
    one2n     = C.pack $ take n ['1' .. ] 
    length' l = C.length l - 1