f = true;
e = false;

while (s = gets) && !e do
  if f then
    f = true;
  else
    puts;
  end
  a = s.split(" ").map(&:to_i);
  a[0].times{|i|
    if i == 0 || i == a[0] - 1 then
      puts "#" * a[1];
    else
      puts "#" + "." * (a[1] - 2) + "#";
    end
  }
end