<>; $x=1e99; for(<>){ $b=0; $b+=$-=ord()-(ord()<65?48:55)-$b for/./g; ++$b; $v=0; $v=$b*$v+ord()-(ord()<65?48:55)for/./g; $x=$v if $x>$v; }print$x