import Control.Applicative
import Control.Monad

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

addReturn :: String -> String
addReturn x = x ++ "\n"

makeFrame :: [Int] -> String
makeFrame all@[h, w] = unlines $ [replicate w '#'] ++ makeContents all ++ [replicate w '#'] 

makeContents :: [Int] -> [String]
makeContents [h, w] = replicate (h-2) $ makeLine w

makeLine :: Int -> String
makeLine w = "#" ++ replicate (w-2) '.' ++ "#"

main = do
    line <- getContents
    mapM_ putStrLn (map makeFrame (shapingData line))
