import math import sys def resolve(): nstr = input() length = len(nstr) n = int(nstr) if length == 2: print(n//3-3) return result = 30 if length - 3 > 0: result += 16*(4**(length-3)-1) head = int(nstr[0]) if head < 3: print(result) return elif head == 3: pass elif head < 6: result += 4**(length-1) print(result) return elif head == 6: result += 4**(length-1) elif head < 9: result += 2 * 4**(length-1) print(result) return else: result += 2 * 4**(length-1) tmp = 1 for c in nstr[1:]: if int(c) < 3: continue elif int(c) < 6: tmp *= 2 elif int(c) < 9: tmp *= 3 else: tmp *= 4 result += tmp print(result) resolve()