main = do
  [h,w] <- map read . words <$> getLine :: IO [Integer]
  getLine
  as <- map read . words <$> getLine :: IO [Integer]
  let f i j n (0:as) r xs = f i j (n+1) as r xs
      f 0 _ _ _ _ _ = []
      f i 0 n as True xs = reverse xs : f (i-1) w n as False []
      f i 0 n as False xs = xs : f (i-1) w n as True []
      f i j n (a:as) r xs = f i (j-1) n (a-1:as) r (n:xs)
  mapM (putStrLn . unwords . map show) $ f h w 1 as True []