import Control.Applicative

main = do
    ss <- words <$>getLine
    let a:b:_ = [read x| x<- ss] ::[Int]
    if a==0 then return ()
    else do
      let o = (take b (repeat '#')) ++ "\n" ++ concat[x++"\n" | x<-(take (a-2) (repeat("#" ++ take (b-2) (repeat '.') ++ "#")))] ++ (take b (repeat '#')) ++ "\n"
      putStrLn $ o
      main