loop do
  height, width = gets.chomp.split.map(&:to_i)
  break if height == 0 && width == 0
  height.times do |h|
    if h == 0 || h == height - 1
      puts '#' * width
    else
      puts '#' + '.' * (width - 2) + '#'
    end
  end
  puts "\n"
end

