def picksort(x, lis, out, a = 0):
  if x == 0:
    out.append(a)
    return
  a *= 10
  for i in xrange(len(lis)):
    tmp = lis[:]
    tmpa = a + lis[i]
    tmp.pop(i)
    picksort(x - 1, tmp, out, tmpa)




a = [0,1,2,3,4,6,7,8,9]
tt = []
picksort(len(a), a, tt)


total = 0
for i in tt:
  tttt = str(i)
  if tttt[0] != '0' and int(tttt[3]) % 2 == 0:
    if int(tttt[2:5]) % 3 == 0 and int(tttt[5:8]) % 13 == 0 and int(tttt[6:]) % 17 == 0:
      tmp = i % 10000 + (i / 10000 * 10 + 5) * 10000
      if int(str(tmp)[4:7]) % 7 == 0 and int(str(tmp)[5:8]) % 11 == 0:
        print tmp
        total += tmp

print total