x = int(input()) a = x // 100 b = (x // 10) % 10 c = x % 10 if a > b and b > c: print(3) elif a < b and b < c: print(2000 + c ** 3) elif a == b == c: print(a * (3 ** a)) else: print(0) # This case is not covered by the examples, but included for completeness.