rect (h:w:_) 
    | h < 3 || w < 3 = replicate h s
    | otherwise = [s] ++ (replicate (h-2) $ ['#'] ++ replicate (w-2) '.' ++ ['#']) ++ [s]
    where s = replicate w '#'

main = interact $ unlines . map (unlines . rect . map read . words) . takeWhile (/="0 0") . lines
