fun main(args: Array<String>) {
    while (true) {
        val inStr = readLine()
        val (h, w) = inStr?.split(' ')?.map { s -> s.toInt() } ?: return

        if ((h == 0) && (w == 0)) {
            return
        }
        printFrame(h, w)
        println()
    }
}

fun printFrame(height:Int, width:Int) {
    val verticalEdge = "#".repeat(width)
    var bodyLine = "#" + ".".repeat(width - 2) + "#"

    println(verticalEdge)
    (1..(height - 2)).map { _ -> println(bodyLine) }
    println(verticalEdge)
}

