ARGF.each_line do |line|
  h, w = line.split.map(&:to_i)
  break if h == 0 && w == 0
  1.upto(h) { |i|
    case i
    when 1, h
      puts '#' * w
    else
      print "##{"." * (w - 2)}#\n"
    end
  }
  puts
end