n = int(input())
print(sum([1 if str(i).count('3') > 0 and str(i).count('5') > 0 and str(i).count('7') > 0 and len(str(i)) == str(i).count('3') + str(i).count('5') + str(i).count('7') else 0 for i in range(1,n+1)]))