let frame h w =
  let rec top_bottom w =
    match w with
    |0 -> print_string "\n"
    |_ -> print_string "#";
          top_bottom (w-1)
  in
  top_bottom w;
  let rec inner w h =
    match h with
    |0 -> ()
    |_ -> print_string "#";
          let rec inner_w w =
            match w with
            |0 -> ()
            |_ -> print_string ".";
                  inner_w (w-1);
          in
          inner_w (w-2);
          print_string "#\n";
          inner w (h-1)
  in
  inner w (h-2);
  top_bottom w;
  print_string "\n"
;;

let rec loop () =
  Scanf.sscanf (read_line()) "%d %d" (fun h w -> if h = 0 || w = 0 then ()
                                                 else
                                                   begin
                                                     frame h w;
                                                     loop()
                                                   end
    )
;;
loop();;
