{$IFDEF NORMAL}
{$H-,I+,OBJECTCHECKS-,Q-,R-,S-}
{$ENDIF NORMAL}
{$IFDEF DEBUG}
{$H-,I+,OBJECTCHECKS-,Q+,R+,S-}
{$ENDIF DEBUG}
{$IFDEF RELEASE}
{$H-,I-,OBJECTCHECKS-,Q-,R-,S-}
{$ENDIF RELEASE}
{$R-}
program zadanie;
const
x='1234567890';
var
a,b : array [1..10000] of char;
c,e : array [1..100000000] of longint;
i,n,k,d,z,p,o,l,l1,max,min : longint;
input,output : text;
code : integer;
s,s1 : string;
begin
assign(input,'input.txt'); reset(input);
assign(output,'output.txt'); rewrite(output);
n:=0; k:=0; d:=0; s:=''; l:=0;
while not eoln(input) do
begin
inc(n);
read(input,a[n]);
end;
readln(input);
while not eof(input) do
begin
inc(k);
read(input,b[k]);
end;
i:=1;
while i<=n do
begin
for o:=i to n do
if pos(a[o],x)<>0 then
s:=s+a[o]
else break;
if a[o]='.' then
begin
for p:=o+2 to n do
if pos(a[p],x)<>0 then
s1:=s1+a[p]
else
break;
val(s,d,code);
val(s1,z,code);
for o:=d to z do
begin
inc(l);
c[l]:=o;
end;
i:=i+(length(s)+length(s1)+2);
end
else if pos(a[i],x)<>0 then
begin
inc(l);
val(s,c[l],code);
inc(i,length(s)-1)
end;
p:=0; o:=0; d:=0; z:=0; s:=''; s1:='';
inc(i);
end;
l1:=l; l:=0; i:=1;
while i<=k do
begin
for o:=i to k do
if pos(b[o],x)<>0 then
s:=s+b[o]
else break;
if b[o]='.' then
begin
for p:=o+2 to k do
if pos(b[p],x)<>0 then
s1:=s1+b[p]
else
break;
val(s,d,code);
val(s1,z,code);
for o:=d to z do
begin
inc(l);
e[l]:=o;
end;
inc(i,length(s)+length(s1)+2);
end
else if pos(b[i],x)<>0 then
begin
inc(l);
val(s,e[l],code);
inc(i,length(s)-1)
end;
p:=0; o:=0; d:=0; z:=0; s:=''; s1:='';
inc(i);
end;
o:=0;
for i:=l+1 to l+l1 do
begin
inc(o);
e[i]:=c[o];
c[o]:=0;
end;
i:=1; o:=0;
repeat
min:=maxlongint;
for i:=1 to l+l1 do
if (e[i]<min) and (e[i]<>0) then min:=e[i];
for i:=1 to l+l1 do
if e[i]=min then e[i]:=0;
if min<>maxlongint then
begin
inc(o);
c[o]:=min;
end;
inc(i);
until min=maxlongint;
l:=l+l1; s:='['; i:=1; o:=0; p:=0;
while i<=l do
begin
if (c[i]=0) and (i<>1) then
break
else
begin
max:=c[i];
for o:=i+1 to l do
if c[o]-max=1 then
begin
max:=c[o];
inc(p);
end
else begin
break;
inc(i);
end;
if max=c[i] then
begin
str(max,s1);
s:=s+s1+', ';
end
else
begin
str(c[i],s1);
s:=s+s1+'..';
str(max,s1);
s:=s+s1+', ';
end;
if c[o]<>max then i:=o
else i:=o+1;
end;
end;
if length(s)=1 then
writeln(output,s,']')
else
begin
s[length(s)]:=']';
delete(s,length(s)-1,1);
writeln(output,s);
end;
close(input);
close(output);
end.