import itertools N = int(input()) cnt = 0 T = list(itertools.product(['0', '3', '6', '9'], repeat=len(str(N)))) for i in range(len(T)): num = int(''.join(T[i])) if num>10 and num<=N: cnt += 1 for i in range(10,min(100,N+1)): a,b = i//10 ,i%10 if((a+b)%3==0 and a%3 != 0): cnt +=1 print(cnt)