n = int(input()) lst = [] while n > 0: n, x = divmod(n, 10) if x > 4: x -= 1 lst.append(x) ans = 0 for i, v in enumerate(lst): ans += v * pow(9, i) print(ans)