#!/usr/bin/python
# -*- coding: utf-8 -*-

from collections import deque

N = int(input())

item = ["3","5","7"]

d = deque([])
Order = 3
for _ in range(0,Order):
    d.append(item[0])

cand = []
cand.append("".join(list(d)))

while True:

    if d == deque([]):
        Order += 1
        for _ in range(0,Order):
            d.append(item[0])

    now = d.pop()

    if now == item[0]:
        d.append(item[1])
        while len(d) < Order:
            d.append(item[0])
        cand.append("".join(list(d)))
#        print("".join(list(d)))
    elif now == item[1]:
        d.append(item[2])
        while len(d) < Order:
            d.append(item[0])
        cand.append("".join(list(d)))
#        print("".join(list(d)))
    elif now == item[2]:
        continue

    # 終了条件
    if int("".join(list(d))) > N:
        break

cnt = 0
for Num in cand:
    if Num.count("3") != 0 and Num.count("5") != 0 and Num.count("7") != 0:
        cnt += 1

print(cnt)