main :: IO ()
main = interact $ unlines . map (convert . map read . words) . init . lines

convert :: [Int] -> String
convert [h,w] = unlines $ [lid] ++ replicate (h-2) mid ++ [lid]
    where lid = replicate w '#'
          mid = "#" ++ replicate (w-2) '.' ++ "#"
