import os
import sys
# 请在此输入您的代码
n = int(input())
sm = 0
for i in range(1, n+1):
sr = str(i)
if '2' not in sr:
sm += 1
print(sm)
import os
import sys
# 请在此输入您的代码
n = int(input())
sm = 0
for i in range(1, n+1):
sr = str(i)
if '2' not in sr:
sm += 1
print(sm)