long long k,t,r;main(i){for(;~scanf("%lld\n",&t);r=!printf(""-5,r))for(k=i=1;t/=10;k*=++i)r+=t%10*k;}