main = do
    s <- fmap (map (map read) . map words . lines) getContents
    mapM_ (mapM_ putStrLn . rect) $ takeWhile (\(a:b:_) -> a /= 0 && b /= 0) s
    where rect (h:w:_) = [(replicate w '#')] ++ (replicate (h-2) ("#" ++ (replicate (w-2) '.') ++ "#")) ++  [(replicate w '#')] ++ [""]

