from math import gcd from collections import Counter def gcds(ls): ret = 0 for i in ls: ret = gcd(ret,i) return ret n = input() c = Counter(n) d = list(int(i) for i in c.keys()) ans = 1 if len(d) == 1: ans = n else: if len(d) == 2 and 0 in d: ans *= c[1] elif gcds(d) != 1: b = gcds(d) if b%3: ans *= b else: ans *= b//3 dsum = 0 for i,j in c.items(): dsum += int(i)*j if dsum%9 == 0: ans *= 9 elif dsum%3 == 0: ans *= 3 print(ans)