let print_a_frame h w =
  let buf = Buffer.create 256 in
  let s1  = (String.make w '#') ^ "\n" in
  let s2  = "#" ^ (if w>2 then String.make (w-2) '.' else "") ^ "#\n" in
  let rec loop i =
    if i > h then Buffer.contents buf
    else if i=1 || i=h then (Buffer.add_string buf s1; loop (i+1))
    else (Buffer.add_string buf s2; loop (i+1))
  in print_endline (loop 1)
    

let () =
  let rec loop () =
    let line = read_line () in
    let h,w = Scanf.sscanf line "%d %d" (fun h w -> h,w) in
    if (h,w) = (0,0) then ()
    else loop (print_a_frame h w);
  in loop ()