n = int(input())
cnt = 0
for k in range(n+1):
for i in range(60):
for j in range(60):
if '3' in str(k) or '3' in str(i) or '3' in str(j):
cnt += 1
print(cnt)
n = int(input())
cnt = 0
for k in range(n+1):
for i in range(60):
for j in range(60):
if '3' in str(k) + str(i) + str(j):
cnt += 1
print(cnt)