makeSquare :: [Int] -> String
makeSquare [h,w] = unlines $ makeSquare' [h,w]
  where 
    makeSquare' [h,w]
      | w <  3  = replicate h $ ws
      | h == 1  = [ws]
      | True    = [ws] ++ (replicate (h-2) ws') ++ [ws]
      where
        ws  = replicate w '#'
        ws' = "#" ++ ( replicate (w - 2) '.' ) ++ "#"
    
main :: IO () 
main = do
  s' <- getLine
  let s = (map read . words) s'
  
  if s == [0,0] then return ()
  else do
    putStrLn $ makeSquare s 
    main