N = int(input())
M = 0
A = []
count = 0

while N != 0:
	if max(0, ((N%10)-1)//2) >= 3:
		A.append(3)
		N = N//10
	elif max(0, ((N%10)-1)//2) >= 2:
		A.append(2)
		N = N//10
	elif max(0, ((N%10)-1)//2) >= 1:
		A.append(1)
		N = N//10
	else:
		A.append(3)
		N = N//10 - 1

#print(A)

exponent = 0
for a in A:
	M += a * (4**exponent)
	exponent +=1

#print(M)

K = M
for x in range(M):
	if (1 in A) and (2 in A) and (3 in A) and not (0 in A):
		count += 1
	K -= 1
#	print("K = " + str(K))
	A  = []
	while K != 0:
		A.append(K%4)
		K = K//4
#	print("count = " + str(count))
#	print("A = " + str(A) )
	
	exponent = 0
	for a in A:
		K += a * (4**exponent)
		exponent +=1


print(count)



