import re
def num2str(n):
return re.split('_', re.sub('\B', '_', str(n)))
from math import factorial
sum = 0
for n in range(10, 10**6):
work = num2str(n)
worksum = 0
for i in work: worksum = worksum + factorial(int(i)s)
if worksum == n: sum = sum + n
print sum