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