loop do
  h, w = gets.split.map(&:to_i)
  break if h == 0 && w == 0
  (1..h).each do |y|
    line =
    if y == 1 || y == h
      '#' * w
    else
      '#' + ('.' * (w - 2)) + '#'
    end
    puts line
  end
  puts
end