from itertools import product N = int(input()) cnt = 0 num = [str(i) for i in range(10)] for i in range(3, 16, 3): if len(str(N)) < i: break for v in product(num, repeat = i//3): if v[0] == '0': continue s = ''.join(v) s = 3 * s if int(s)<=N: cnt += 1 print(cnt)