main :: IO ()
main = interact $ unlines . map (box . strToIntList) . takeWhile (/="0 0") . lines

strToIntList :: String -> (Int, Int)
strToIntList s = (x, y) where x:y:_ = map read . words $ s

box :: (Int, Int) -> String
box = unlines . rows

rows :: (Int, Int) -> [String]
rows (h, w)
    | h >= 3 && w >= 3  = [cover] ++ contents ++ [cover]
    | otherwise         = replicate h cover
    where cover    = replicate w '#'
          contents = replicate (h-2) $ "#" ++ replicate (w-2) '.' ++ "#"