program pil_10_16_b(input,output);
const
	n = 30;
  k = 5;
type
	str = packed array [1..k] of char;
var
	mas : array [1..n] of str;
  m : str;
  b : array [1..n] of boolean;
  i,j,WordCount : integer;
  c : char;
begin
  i := 1;
	repeat
  	read(c);
		j := 1;
    while (c<>',')and(c<>'.') do begin
    	mas[i][j] := c;
      j := j+1;
      read(c);
    end;
    i := i+1;
  until c='.';
  WordCount := i-1;

	m := mas[WordCount];
  for i:=WordCount downto 1 do
  	if mas[i]<m then begin
    	m := mas[i];
      b[i] := true;
    end
    else
			b[i] := false;

  m := mas[1];
  for i:=1 to WordCount do
  	if mas[i]>m then begin
    	if b[i] then WriteLn(mas[i]);
      m := mas[i];
    end;
end.