from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N = int(input()) ans = 0 for i in range(1,100000): s = str(i) if s[0]=='0': continue s = int(3*s) if s<=N: ans += 1 else: break print(ans)