solve :: [Int] -> [String]
solve (x : y : xs)
  | x == 0 && y == 0 = []
  | otherwise = (replicate y '#') : (map ((++['#']) . ('#':)) (replicate (x-2) $ replicate (y-2) '.'))	++ [replicate y '#'] ++ [""]++ solve xs

main = getContents >>= mapM_ putStrLn . solve . map read . words