import Control.Applicative
import Control.Monad

rInt s = read s :: Int

main  = do
	ss <- (map (map rInt) . map words . lines) <$> getContents
	mapM (mapM putStrLn . frame) $ takeWhile (\(h:(w:_)) -> h/=0 && w/=0) ss 
		where frame (h:(w:_)) = [hframe w] ++ (replicate (h-2) (hinner w)) ++ [hframe w] ++ [""]
		      hframe w = replicate w '#'
		      hinner w = ['#'] ++ (replicate (w-2) '.') ++ ['#']