<>; [sort@a=/./g]~~@a&&${ $x|=$d{$a[-1]}|=$d{$_}.1x@a for reverse a..$a[0]; } for sort<>; print 0+length$x