main = getContents >>= putOut.formatOut.map calc.formatIn
  where putOut s | last s == '\n' = putStr s
                 | otherwise      = putStrLn s

formatIn :: String -> [[Int]]
formatIn = map ((map toInt).words).takeWhile (/="0 0").lines
  where toInt =read :: String -> Int

formatOut :: [String] -> String
formatOut = unlines

calc :: [Int] -> String
calc (h:w:_) = unlines $ (shr w) ++ replicate (h-2) (dot (w-2)) ++ (shr w)
  where shr n = [replicate n '#']
        dot n = (++"#").('#':) $replicate n '.'