makeFrame :: Int -> Int -> [String]
makeFrame h w = [if y == 1 || y == h then take w $ repeat '#'
                 else [if x == 1 || x == w then '#' else '.' | x <- [1..w]] | y <- [1..h]]

printFrame :: [String] -> IO ()
printFrame frame = mapM_ putStrLn frame

main :: IO ()
main = do
  input <- getLine
  let [h, w] = map read $ words input :: [Int]
  if h == 0 && w == 0
    then do return ()
    else do
    mapM_ putStrLn $ makeFrame h w
    putStrLn ""
    main