{-# LANGUAGE BangPatterns #-}

module Main where

import Data.Char
import Data.List
import Control.Monad
import Control.Applicative
import Text.Printf


readInt :: IO Int
readInt = read <$> (input `seq` input)
    where input = do
            !c <- getChar
            if isDigit c || c == '-'
                then (c :) <$> input
                else return []

prints :: Show a => [a] -> IO ()
prints as = putStrLn $ concat $ intersperse " " $ map show as

main = do
    [h, w] <- replicateM 2 readInt
    if h == 0 && w == 0
        then return ()
        else draw h w >> putStrLn "" >> main

draw h w = putStrLn (replicate w '#') >> inside >> putStrLn (replicate w '#')
  where inside = replicateM (h-2) (putStr "#" >> replicateM (w-2) (putStr ".") >> putStrLn "#")
