const
  Inp1  = 'input1.txt';
  Inp2  = 'input2.txt';
  Out1  = 'output1.txt';
type
 Pty = ^ty;
 ty = record
   name : Char;
   next : Pty;
 end;

var
  Root1,Root2,Nroot       : Pty;
  f1,f2                   : text;
{--------------------------------------------}
procedure Insert(var NRoot:pty; Tec : pty);
var
Pred,sled : Pty;
begin
  if Tec^.name < Nroot^.name Then begin
     Tec^.next := Nroot;
     Nroot := Tec;
  end
  else begin
     Pred :=  Nroot;
     Sled := Nroot^.next;
     while (Tec^.name >= Sled^.name) and (Sled <> nil) do begin
        Pred := Sled;
        Sled := Sled^.next;
     end;
     pred^.next := Tec;
     Tec^.next  := Sled;
  end;
end;
{--------------------------------}

{read m from file==========================================}{P1}
Procedure ReadM(var root : pty;inp : string);
var
Tec : Pty;

begin
  Assign(f1,Inp);
  Reset(f1);
  New(tec);
  Read(f1,Tec^.Name);
  Root := Tec;
  Root^.next := nil;
  While not(Eof(F1)) do begin
    New(Tec);
    Read(f1,Tec^.Name);
    Insert(Root,Tec);
  end;
  close(f1);
end;
{==========================================}
{==========================================}    {p2}
Procedure OuttoFils(Root : pty);
begin
  Assign(F2,Out1);
  ReWrite(f2);

  {write to files}
  while root<>nil do Begin
    Write(f2,Root^.name);
    root := root^.next;
  end;

  close(f2);
end;
{==========================================}
Procedure P3(Root1,Root2:pty;var NewRoot : pty);      {p3}
var
  Tec,Sled : Pty;
begin
  NewRoot := Root1;

  Tec := Root2;
  While Tec <> nil do begin
    Sled := Tec^.next;
    insert(NewRoot,Tec);
    Tec := Sled;
  end;
end;
{==========================================}
begin
  ReadM(Root1,inp1);
  ReadM(Root2,inp2);
  P3(Root1,Root2,NRoot);
  OuttoFils(NRoot);
end.