import java.math.BigInteger;
import java.util.Scanner;
import static java.math.BigInteger.*;
public class Main{
public static void main(String[] args){
int i, num[] = {1, 2, 6, 30, 210, 2310, 30030, 510510, 9699690, 223092870}, toDec;
BigInteger out= new BigInteger("0"), temp= new BigInteger("0");
Scanner scanner = new Scanner(System.in);
String str = scanner.next();
for(i=str.length()-1; i>=0; i--){
toDec = num[str.length() - 1 - i];
if(str.charAt(i)>47 && str.charAt(i)<58){
temp = BigInteger.valueOf(str.charAt(i)-48);
out = out.add(temp.multiply(BigInteger.valueOf(toDec)));
}else{
temp = valueOf(str.charAt(i)-87);
out = out.add(temp.multiply(BigInteger.valueOf(toDec)));
}
}
System.out.println(out);
}
}