x = gets()
y = x.split()
h = y[0].to_i
w = y[1].to_i

until h == 0 && w == 0
 i = 1
 while i <= h
  if i == 1 || i == h
  puts "#" * w
  i += 1
  else
  puts "#" + "." * (w - 2) + "#"
  i += 1
  end

 end
 puts ""
 x = gets()
 y = x.split()
 h = y[0].to_i
 w = y[1].to_i
end
