module Main where

none = -1

solve (h:w:_:list) = println $ process (take h $ repeat w) list

process _ [] = []
process space (a:list) =
  let (pos, sp) = find a space in
  pos : process sp list

find a [] = (none, [])
find a (s:space) =
  if (a <= s)
  then (1, (s - a) : space)
  else
    let (pos, sp) = find a space
    in (if pos == none then pos else pos + 1, s:sp)

parse :: [Char] -> [Int]
parse s = map read $ words s

println = concatMap (\a -> show a ++ ['\n'])

main = do
  s <- readFile "billboard.in"
  writeFile "billboard.out" $ solve $ parse s
