object Main extends App {
  val sc = new java.util.Scanner(System.in)
  printFrame(sc.nextInt(), sc.nextInt())

  def printFrame(h: Int, w: Int): Unit = {
    (h, w) match {
      case (0, 0) => sc.close()
      case _ =>
        for (i <- 1 to h) i match {
          case i if i == 1 || i == h => println("#" * w)
          case _ => println("#" + ("." * (w - 2)) + "#")
        }
        println()
        printFrame(sc.nextInt(),sc.nextInt())
    }
  }
}